Last active
July 10, 2019 22:55
-
-
Save wlach/2fbe93ee57b0acb87bf69cdb1488ccd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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