Skip to content

Commit

Permalink
Use exdoc:loaded to reload mermaid graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jan 24, 2025
1 parent 85d2e16 commit 4c1e9da
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions lib/elixir/scripts/elixir_docs.exs
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,19 @@ canonical = System.fetch_env!("CANONICAL")
before_closing_body_tag: fn
:html ->
"""
<script defer src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js"></script>
<script>
function mermaidLoaded() {
mermaid.initialize({
startOnLoad: false,
theme: document.body.className.includes("dark") ? "dark" : "default"
});
let initialized = false;
window.addEventListener("exdoc:loaded", () => {
if (!initialized) {
mermaid.initialize({
startOnLoad: false,
theme: document.body.className.includes("dark") ? "dark" : "default"
});
initialized = true;
}
let id = 0;
for (const codeEl of document.querySelectorAll("pre code.mermaid")) {
const preEl = codeEl.parentElement;
Expand All @@ -210,9 +217,8 @@ canonical = System.fetch_env!("CANONICAL")
preEl.remove();
});
}
}
});
</script>
<script async src="https://cdn.jsdelivr.net/npm/[email protected]/dist/mermaid.min.js" onload="mermaidLoaded();"></script>
"""

_ ->
Expand Down

0 comments on commit 4c1e9da

Please sign in to comment.