-
Notifications
You must be signed in to change notification settings - Fork 3
/
mermaid.js
34 lines (31 loc) · 1.18 KB
/
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
import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.esm.min.mjs';
mermaid.initialize({
startOnLoad: false,
theme: 'base',
securityLevel: 'loose',
flowchart: { useMaxWidth: false, useMaxHeight: false }
});
function renderMermaidDiagrams() {
const diagrams = document.querySelectorAll('.language-mermaid');
diagrams.forEach((element, index) => {
try {
const graphDefinition = element.textContent;
const graphId = `mermaid-diagram-${index}`;
mermaid.render(graphId, graphDefinition)
.then(({svg, bindFunctions}) => {
element.innerHTML = svg;
bindFunctions?.(element);
})
.catch(error => {
console.error(`Error rendering Mermaid diagram ${index}:`, error);
element.innerHTML = `<p>Error rendering diagram: ${error.message}</p>`;
});
} catch (error) {
console.error(`Error processing Mermaid diagram ${index}:`, error);
}
});
}
proc_htmx('.language-mermaid', () => {
renderMermaidDiagrams()
// setTimeout(renderMermaidDiagrams, 100);
});