mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-24 17:59:39 +02:00
refactor: Revert type change for renderer
This commit is contained in:
@@ -58,7 +58,7 @@ export class Diagram {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async render(id: string, version: string) {
|
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() {
|
getParser() {
|
||||||
|
@@ -100,8 +100,7 @@ export type DrawDefinition = (
|
|||||||
text: string,
|
text: string,
|
||||||
id: string,
|
id: string,
|
||||||
version: string,
|
version: string,
|
||||||
diagramObject: Diagram,
|
diagramObject: Diagram
|
||||||
error: Error | null,
|
|
||||||
) => void | Promise<void>;
|
) => void | Promise<void>;
|
||||||
|
|
||||||
export interface ParserDefinition {
|
export interface ParserDefinition {
|
||||||
|
@@ -17,14 +17,12 @@ export const draw = (
|
|||||||
id: string,
|
id: string,
|
||||||
version: string,
|
version: string,
|
||||||
_diagramObject: Diagram,
|
_diagramObject: Diagram,
|
||||||
error: Error | null = null
|
error?: Error
|
||||||
) => {
|
) => {
|
||||||
log.debug('renering svg for syntax error\n');
|
log.debug('renering svg for syntax error\n');
|
||||||
|
|
||||||
const svg: SVG = selectSvgElement(id);
|
const svg: SVG = selectSvgElement(id);
|
||||||
|
|
||||||
const g: Group = svg.append('g');
|
const g: Group = svg.append('g');
|
||||||
if (error && error.message?.includes('KaTeX')) {
|
if (error?.message?.includes('KaTeX')) {
|
||||||
const title = error.message.split(': ')[0];
|
const title = error.message.split(': ')[0];
|
||||||
const body = error.message.replace(/[A-z]*:/, '').replace('KaTeX parse ', '');
|
const body = error.message.replace(/[A-z]*:/, '').replace('KaTeX parse ', '');
|
||||||
g.append('foreignObject')
|
g.append('foreignObject')
|
||||||
@@ -36,7 +34,10 @@ export const draw = (
|
|||||||
.html(`<div style="font-size: 26px; margin-bottom: 8px">${title}</div><div>${body}</div>`);
|
.html(`<div style="font-size: 26px; margin-bottom: 8px">${title}</div><div>${body}</div>`);
|
||||||
svg.attr('height', 100);
|
svg.attr('height', 100);
|
||||||
svg.attr('width', 500);
|
svg.attr('width', 500);
|
||||||
} else {
|
svg.attr('viewBox', '0 0 500 100');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
svg.attr('viewBox', '0 0 2412 512');
|
svg.attr('viewBox', '0 0 2412 512');
|
||||||
configureSvgSize(svg, 100, 512, true);
|
configureSvgSize(svg, 100, 512, true);
|
||||||
|
|
||||||
@@ -96,7 +97,6 @@ export const draw = (
|
|||||||
.attr('font-size', '100px')
|
.attr('font-size', '100px')
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.text(`mermaid version ${version}`);
|
.text(`mermaid version ${version}`);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const renderer = { draw };
|
export const renderer = { draw };
|
||||||
|
@@ -435,7 +435,7 @@ const render = async function (
|
|||||||
// -------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------
|
||||||
// Draw the diagram with the renderer
|
// Draw the diagram with the renderer
|
||||||
try {
|
try {
|
||||||
await diag.renderer.draw(text, id, version, diag, null);
|
await diag.renderer.draw(text, id, version, diag);
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
errorRenderer.draw(text, id, version, diag, e);
|
errorRenderer.draw(text, id, version, diag, e);
|
||||||
throw e;
|
throw e;
|
||||||
|
Reference in New Issue
Block a user