Open minikinl opened 3 years ago
mermaid.parseError = console.log;
According to this guides, I'm trying to rewrite parseError
method of mermaid
, but it seems just invoked in mermaid.init
, when error occurred in mermaid.render
, the parseError
won't invoked:
// this statement will cause error
mermaid.render('graph', 'some invalid script');
// but nothing output in console
https://mermaid-js.github.io/mermaid/#/usage?id=advanced-usage
// src/mermaidAPI.js
const render = function (id, _txt, cb, container) {
// some codes here ....
try {
switch (graphType) { ... }
} catch (e) {
// errorRenderer.setConf(cnf.class);
errorRenderer.draw(id, pkg.version);
throw e;
}
// some codes here ...
const node = select('#d' + id).node();
if (node !== null && typeof node.remove === 'function') {
select('#d' + id)
.node()
.remove();
}
}
I think problem is an element was created and has been append to document.body
before try...catch...
block,
But you throw this err again inside catch
block, so that the element cleaner behind catch
won't executed.
I'm using
mermaid
to generate SVG in markdown. An error image was always shown when render error, eg:An error occurred, this is what i need:
But, an error message that I don’t need will also appear at the end of the DOM tree:
In my case, this ERROR IMAGE was not needed, of course it can be removed just by:
But this method does not look elegant. Is there a more appropriate way, such as providing custom options to prevent draw an image ? eg:
This error message may render by these statements in the source code:
https://github.com/mermaid-js/mermaid/blob/8af36b742ee81fb4894397f1f6b60fdbc011a7fb/src/mermaidAPI.js#L436
I am looking for a way to prevent this default behavior, it may be similar to:
thanks.