-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreveal-mermaid.js
34 lines (31 loc) · 1.15 KB
/
reveal-mermaid.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
mermaid.initialize({
startOnLoad: false,
logLevel: 3,
});
Reveal.on('ready', event => {
console.log('asyncMermaidRender');
const graphs = document.getElementsByClassName('mermaid');
graphs.forEach((item, index) => {
// already proceeded
if (item.getElementsByTagName('svg') && item.getElementsByTagName('svg').length > 0) {
return;
}
const graphCode = item.innerText.trim();
const mermaidDiv = document.createElement('div');
mermaidDiv.classList.add('mermaid');
mermaidDiv.setAttribute('data-processed', 'true');
try {
// item.innerText ignores html elements added by revealjs highlight plugin.
mermaid.mermaidAPI.render('theGraph' + index, graphCode, function(svgCode) {
mermaidDiv.innerHTML = svgCode;
});
let parentDiv = document.createElement('div');
parentDiv.appendChild(mermaidDiv);
item.parentNode.parentNode.insertBefore(parentDiv, item.parentNode);
item.parentNode.remove();
}
catch(err) {
console.error('Cannot render mermaid diagram ', err.message);
}
});
});