mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 04:15:21 +00:00
24 lines
662 B
JavaScript
24 lines
662 B
JavaScript
|
import {random} from '../utils.js';
|
||
|
|
||
|
export async function renderMermaid(els) {
|
||
|
if (!els || !els.length) return;
|
||
|
|
||
|
const {mermaidAPI} = await import(/* webpackChunkName: "mermaid" */'mermaid');
|
||
|
|
||
|
mermaidAPI.initialize({
|
||
|
startOnLoad: false,
|
||
|
theme: 'neutral',
|
||
|
securityLevel: 'strict',
|
||
|
});
|
||
|
|
||
|
for (const el of els) {
|
||
|
mermaidAPI.render(`mermaid-${random(12)}`, el.textContent, (svg, bindFunctions) => {
|
||
|
const div = document.createElement('div');
|
||
|
div.classList.add('mermaid-chart');
|
||
|
div.innerHTML = svg;
|
||
|
if (typeof bindFunctions === 'function') bindFunctions(div);
|
||
|
el.closest('pre').replaceWith(div);
|
||
|
});
|
||
|
}
|
||
|
}
|