refactor: Revert type change for renderer

This commit is contained in:
Sidharth Vinod
2023-12-07 00:17:53 +05:30
parent 8d90815862
commit 0d98e6ca53
4 changed files with 61 additions and 62 deletions

View File

@@ -58,7 +58,7 @@ export class Diagram {
}
async render(id: string, version: string) {
await this.renderer.draw(this.text, id, version, this, null);
await this.renderer.draw(this.text, id, version, this);
}
getParser() {

View File

@@ -100,8 +100,7 @@ export type DrawDefinition = (
text: string,
id: string,
version: string,
diagramObject: Diagram,
error: Error | null,
diagramObject: Diagram
) => void | Promise<void>;
export interface ParserDefinition {

View File

@@ -17,14 +17,12 @@ export const draw = (
id: string,
version: string,
_diagramObject: Diagram,
error: Error | null = null
error?: Error
) => {
log.debug('renering svg for syntax error\n');
const svg: SVG = selectSvgElement(id);
const g: Group = svg.append('g');
if (error && error.message?.includes('KaTeX')) {
if (error?.message?.includes('KaTeX')) {
const title = error.message.split(': ')[0];
const body = error.message.replace(/[A-z]*:/, '').replace('KaTeX parse ', '');
g.append('foreignObject')
@@ -36,7 +34,10 @@ export const draw = (
.html(`<div style="font-size: 26px; margin-bottom: 8px">${title}</div><div>${body}</div>`);
svg.attr('height', 100);
svg.attr('width', 500);
} else {
svg.attr('viewBox', '0 0 500 100');
return;
}
svg.attr('viewBox', '0 0 2412 512');
configureSvgSize(svg, 100, 512, true);
@@ -96,7 +97,6 @@ export const draw = (
.attr('font-size', '100px')
.style('text-anchor', 'middle')
.text(`mermaid version ${version}`);
}
};
export const renderer = { draw };

View File

@@ -435,7 +435,7 @@ const render = async function (
// -------------------------------------------------------------------------------
// Draw the diagram with the renderer
try {
await diag.renderer.draw(text, id, version, diag, null);
await diag.renderer.draw(text, id, version, diag);
} catch (e: any) {
errorRenderer.draw(text, id, version, diag, e);
throw e;