use mermaid.init() to render diagrams for SPA.

mermaid.initialize({startOnLoad: true}) relies on the DOMContentLoaded
event to trigger rendering of markdown to svg. mermaid.init() bypasses
this behavior, but is deprecated.
This commit is contained in:
brendan 2022-11-27 23:46:43 +08:00
parent 9d71041aca
commit 3cb51a4289

View File

@ -147,6 +147,19 @@
}
{{end}}
{{if $data.enableMermaid | default $.Site.Data.config.enableMermaid}}
var els = document.getElementsByClassName("mermaid");
if (els.length > 0) {
import('https://unpkg.com/mermaid@9/dist/mermaid.esm.min.mjs').then(
(obj) => {
// init forces mermaid to render mermaid markdown without waiting
// for DOMContentLoaded event
obj.default.init();
}
)
}
{{end}}
}
const init = (doc = document) => {