mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-21 06:53:17 +08:00
feat(katex): improved handling of KaTeX errors
This commit is contained in:
parent
1db4230d35
commit
825f50299a
@ -1,6 +1,7 @@
|
|||||||
/** Created by knut on 14-12-11. */
|
/** Created by knut on 14-12-11. */
|
||||||
import { select } from 'd3';
|
import { select } from 'd3';
|
||||||
import { log } from './logger';
|
import { log } from './logger';
|
||||||
|
import * as configApi from './config';
|
||||||
|
|
||||||
const conf = {};
|
const conf = {};
|
||||||
|
|
||||||
@ -22,15 +23,28 @@ export const setConf = function (cnf) {
|
|||||||
*
|
*
|
||||||
* @param {string} id The text for the error
|
* @param {string} id The text for the error
|
||||||
* @param {string} ver The version
|
* @param {string} ver The version
|
||||||
|
* @param {Error} error The caught error
|
||||||
*/
|
*/
|
||||||
export const draw = (id, ver) => {
|
export const draw = (id, ver, error = null) => {
|
||||||
try {
|
try {
|
||||||
log.debug('Renering svg for syntax error\n');
|
log.debug('Renering svg for syntax error\n');
|
||||||
|
|
||||||
|
const cnf = configApi.getConfig();
|
||||||
const svg = select('#' + id);
|
const svg = select('#' + id);
|
||||||
|
|
||||||
const g = svg.append('g');
|
const g = svg.append('g');
|
||||||
|
|
||||||
|
if (error && error.message.includes('KaTeX')) {
|
||||||
|
const title = error.message.split(': ')[0];
|
||||||
|
const body = error.message.replace(/[A-z]*:/, '').replace('KaTeX parse ', '');
|
||||||
|
g.append('foreignObject')
|
||||||
|
.attr('width', 2000)
|
||||||
|
.attr('height', 500)
|
||||||
|
.append('xhtml:div')
|
||||||
|
.style('font-size', '70px')
|
||||||
|
.style('color', cnf.themeVariables.errorTextColor)
|
||||||
|
.html(`<h1>${title}</h1><p>${body}</p>`);
|
||||||
|
} else {
|
||||||
g.append('path')
|
g.append('path')
|
||||||
.attr('class', 'error-icon')
|
.attr('class', 'error-icon')
|
||||||
.attr(
|
.attr(
|
||||||
@ -87,6 +101,7 @@ export const draw = (id, ver) => {
|
|||||||
.attr('font-size', '100px')
|
.attr('font-size', '100px')
|
||||||
.style('text-anchor', 'middle')
|
.style('text-anchor', 'middle')
|
||||||
.text('mermaid version ' + ver);
|
.text('mermaid version ' + ver);
|
||||||
|
}
|
||||||
|
|
||||||
svg.attr('height', 100);
|
svg.attr('height', 100);
|
||||||
svg.attr('width', 400);
|
svg.attr('width', 400);
|
||||||
|
@ -499,7 +499,7 @@ const render = function (id, _txt, cb, container) {
|
|||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// errorRenderer.setConf(cnf.class);
|
// errorRenderer.setConf(cnf.class);
|
||||||
errorRenderer.draw(id, pkg.version);
|
errorRenderer.draw(id, pkg.version, e);
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user