Skip to content

Commit

Permalink
support mermaid darktheme
Browse files Browse the repository at this point in the history
HidegonSan committed Nov 29, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 2825607 commit b21ac7e
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion layouts/partials/head/mermaid.html
Original file line number Diff line number Diff line change
@@ -15,15 +15,31 @@

<script>
document.addEventListener("DOMContentLoaded", async function() {
mermaid.initialize({ startOnLoad: false })
let mermaid_theme = "default";

if (localStorage.getItem("pref-theme") === "dark") {
mermaid_theme = "dark"
} else if (localStorage.getItem("pref-theme") === "light") {
mermaid_theme = "default"
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
mermaid_theme = "dark"
}

mermaid.initialize({
theme: mermaid_theme,
startOnLoad: false
})

await mermaid.run({
querySelector: ".language-mermaid, .mermaid",
suppressErrors: true,
})

document.querySelectorAll(".language-mermaid").forEach(function(e) {
e.style.cssText += "background: none !important; text-align: center;"
e.nextElementSibling.style.cssText += "display: none !important;"
})

document.querySelectorAll(".mermaid").forEach(function(e) {
e.style.cssText += "text-align: center;"
})

0 comments on commit b21ac7e

Please sign in to comment.