ectorAll('#article-container .mermaid-wrap') if ($mermaidWrap.length) { window.runMermaid = () => { window.loadMermaid = true const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default' Array.from($mermaidWrap).forEach((item, index) => { const mermaidSrc = item.firstElementChild const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n' const mermaidID = 'mermaid-' + index const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => { mermaidSrc.insertAdjacentHTML('afterend', svgCode) }) }) } const loadMermaid = () => { window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid) } window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid) } })()