mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-21 06:53:17 +08:00
refactor: Cleanup error renderer
This commit is contained in:
parent
70b948fd17
commit
1d86cf01ad
@ -2,10 +2,9 @@ import { log } from '../../logger.js';
|
|||||||
import type { Group, SVG } from '../../diagram-api/types.js';
|
import type { Group, SVG } from '../../diagram-api/types.js';
|
||||||
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
import { selectSvgElement } from '../../rendering-util/selectSvgElement.js';
|
||||||
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
import { configureSvgSize } from '../../setupGraphViewbox.js';
|
||||||
import type { Diagram } from '../../Diagram.js';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws a an info picture in the tag with id: id based on the graph definition in text.
|
* Draws an info picture in the tag with id: id based on the graph definition in text.
|
||||||
*
|
*
|
||||||
* @param _text - Mermaid graph definition.
|
* @param _text - Mermaid graph definition.
|
||||||
* @param id - The text for the error
|
* @param id - The text for the error
|
||||||
@ -16,15 +15,15 @@ export const draw = (
|
|||||||
_text: string,
|
_text: string,
|
||||||
id: string,
|
id: string,
|
||||||
version: string,
|
version: string,
|
||||||
_diagramObject: Diagram,
|
_diagramObject: unknown,
|
||||||
error?: Error
|
error?: Error
|
||||||
) => {
|
) => {
|
||||||
log.debug('renering svg for syntax error\n');
|
log.debug('rendering 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?.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.slice(title.length + 2).replace('KaTeX parse ', '');
|
||||||
g.append('foreignObject')
|
g.append('foreignObject')
|
||||||
.attr('height', 100)
|
.attr('height', 100)
|
||||||
.attr('width', 500)
|
.attr('width', 500)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user