Martin Kavalar / May 02 2021
Mermaid.js
Example using the Observable Runtime, taken from https://observablehq.com/@oogetyboogety/mermaid-js.
mermaid`
stateDiagram-v2
[*] --> Still
Still --> [*]
Still --> Moving
Moving --> Still
Moving --> Crash
Crash --> [*]
`
Observable Javascript
mermaidJs = require('mermaid@8.7/dist/mermaid.min.js')
Observable Javascript
viewof mermaidContainer = html`<div id="mermaid" />`
Observable Javascript
mermaid = function (values) {
const div = (viewof mermaidContainer); //document.getElementById('mermaid');
if (!div) {
throw 'Cannot find div with id "mermaid"';
}
const src = String.raw(values).trim();
const id = "mmd" + Math.round(Math.random() * 10000);
div.append(html`<div id="${id}" />`);
try {
const result = mermaidJs.render(id, src, undefined);
return svg([result]);
} catch (ex) {
console.error(ex);
throw ex;
}
}
Observable Javascript