-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for dynamic light/dark theme #78
Comments
fwiw I have got this working in a hacky way like this: in conf.py, with javascript pulled out to separate block for the sake of syntax highlighting: mermaid_version = None
mermaid_use_local = "https://example.com"
mermaid_init_js = """(below)""" import mermaid from 'https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.esm.min.mjs'
const make_config = () => {
let prefersDark = localStorage.getItem('theme') === 'dark' || (localStorage.getItem('theme') === null && window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
return({
startOnLoad:false,
darkMode: prefersDark,
theme: prefersDark ? "dark" : "default"
})
}
const init_mermaid = () => {
let graphs = document.querySelectorAll(".mermaid");
[...graphs].forEach((element) => {
if (!element.hasAttribute("data-source")) {
element.setAttribute("data-source", element.innerText);
}
if (element.hasAttribute("data-processed")) {
let new_elt = document.createElement("pre");
let graph_source = element.getAttribute("data-source");
new_elt.appendChild(document.createTextNode(graph_source));
new_elt.classList.add("mermaid");
new_elt.setAttribute("data-source", graph_source);
element.replaceWith(new_elt);
}
});
let config = make_config()
mermaid.initialize(config);
mermaid.run();
}
init_mermaid();
let theme_observer = new MutationObserver(init_mermaid);
let body = document.getElementsByTagName("body")[0];
theme_observer.observe(body, {attributes: true});
window.theme_observer = theme_observer; This is basically designed for furo, watching the I have to break the mermaid url in |
In our diagrams, I used the Mermaid base theme and customized it. It's not perfect, but it's better than the default. CodePreviewYou can copy-paste the code into https://www.mermaidchart.com/play for a live preview, although you will need to change the config from a dict to YAML. Details are available in the Mermaid docs, Customizing Themes with |
As explained here https://twitter.com/hynek/status/1460241865652027397 and detailed https://pradyunsg.me/furo/customisation/colors/#how-light-and-dark-mode-work
The text was updated successfully, but these errors were encountered: