File tree Expand file tree Collapse file tree 1 file changed +22
-16
lines changed Expand file tree Collapse file tree 1 file changed +22
-16
lines changed Original file line number Diff line number Diff line change @@ -197,28 +197,34 @@ config = [
197197 before_closing_body_tag: fn
198198 :html ->
199199 """
200- <script>
201- function mermaidLoaded() {
202- mermaid.initialize({
203- startOnLoad: false,
204- theme: document.body.className.includes("dark") ? "dark" : "default"
205- });
206- let id = 0;
207- for (const codeEl of document.querySelectorAll("pre code.mermaid")) {
200+ <script defer src="https://cdn.jsdelivr.net/npm/[email protected] /dist/mermaid.min.js"></script> 201+ <script>
202+ let initialized = false;
203+
204+ window.addEventListener("exdoc:loaded", () => {
205+ if (!initialized) {
206+ mermaid.initialize({
207+ startOnLoad: false,
208+ theme: document.body.className.includes("dark") ? "dark" : "default"
209+ });
210+ initialized = true;
211+ }
212+
213+ let id = 0;
214+ for (const codeEl of document.querySelectorAll("pre code.mermaid")) {
208215 const preEl = codeEl.parentElement;
209216 const graphDefinition = codeEl.textContent;
210217 const graphEl = document.createElement("div");
211218 const graphId = "mermaid-graph-" + id++;
212219 mermaid.render(graphId, graphDefinition).then(({svg, bindFunctions}) => {
213- graphEl.innerHTML = svg;
214- bindFunctions?.(graphEl);
215- preEl.insertAdjacentElement("afterend", graphEl);
216- preEl.remove();
220+ graphEl.innerHTML = svg;
221+ bindFunctions?.(graphEl);
222+ preEl.insertAdjacentElement("afterend", graphEl);
223+ preEl.remove();
217224 });
218- }
219- }
220- </script>
221- <script async src="https://cdn.jsdelivr.net/npm/[email protected] /dist/mermaid.min.js" onload="mermaidLoaded();"></script> 225+ }
226+ });
227+ </script>
222228 """
223229
224230 _ ->
You can’t perform that action at this time.
0 commit comments