Mermaid & All & Check
Shared by MinamotoYoi
check all your mermaid graph status original project: https://github.com/knsv/mermaid
Script
const reg = /(\s*)(```) *(mermaid) *\n?([\s\S]+?)\s*(\2)(\n+|$)/g;
var all = editor.getText();
var targets = all.match(reg);
if(!targets) {
ui.alert('no mermaid graph detected!');
return;
}
var finalContent = '';
for(var i = 0; i < targets.length; i++) {
finalContent = finalContent + targets[i].replace(reg, function (raw, start, startQuote, lang, content, endQuote, end) {
return '<div class="mermaid">\n' + content + '\n</div>\n<hr>\n';
});
}
finalContent = '<!DOCTYPE html>\n<html>\n<head>\n <title>mermaid</title>\n <script src="https://unpkg.com/mermaid@8.0.0-rc.8/dist/mermaid.min.js"></script>\n <script>mermaid.initialize({startOnLoad:true, theme:"dark"});</script>\n</head>\n<body style="background-color: black">\n' + finalContent + '</body>\n</html>';
webBrowser.loadHTML(finalContent);