Skip to content

Instantly share code, notes, and snippets.

@wlach
Last active July 10, 2019 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wlach/2fbe93ee57b0acb87bf69cdb1488ccd0 to your computer and use it in GitHub Desktop.
Save wlach/2fbe93ee57b0acb87bf69cdb1488ccd0 to your computer and use it in GitHub Desktop.
const MERMAID = 'https://unpkg.com/mermaid@8.0.0/dist/mermaid.min.js'
const loadResource = url => new Promise((resolve) => {
const head = document.getElementsByTagName('head')[0];
const theScript = document.createElement('script');
theScript.src = url;
theScript.onload = () => {
resolve();
};
head.appendChild(theScript);
})
Promise.all([loadResource(MERMAID)])
.then(() => {
window.mermaidPlugin = {}
window.mermaidPlugin.evaluateMermaid = (input) => {
const elem = iodide.output.element('div');
const id = "iodide-mermaidChart-" + Date.now();
elem.setAttribute("class", "iodideMermaid");
mermaid.mermaidAPI.render(id, input, (svgCode) => elem.innerHTML = svgCode);
return elem
}
window.iodide.addOutputRenderer({
shouldRender: val => { return val.getAttribute('class') === 'iodideMermaid'; },
render: (val) => {
return val.innerHTML;
},
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment