-
-
Notifications
You must be signed in to change notification settings - Fork 367
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
Add Mermaid theme switch respecting dark/light toggle #376
Comments
If there is a way to determine if dark-mode is enabled from the shortcode, you can modify it to toggle this line
|
Thanks! Interesting (didn't know that), I will have a look into that (I think it's possible). |
I just played a little with it. I "abused" <!-- layouts/shortcodes/mermaid.html -->
<!-- ignore the figure and caption part -->
{{ if .Page.Params.mermaid -}}
<figure{{ with .Get "figure_class" }} class="{{.}}"{{ end }}>
<div class="text-center">
<div class="logo-dark d-none">
<div class="mermaid{{ with .Get "class" }} {{ . }}{{ end }}">
%%{init: { 'theme': 'dark' } }%%
{{ $data := replaceRE "(^\\s+```)" "" .Inner -}}
{{ replaceRE "(```\\s+$)" "" $data -}}
</div>
</div>
<div class="logo-light">
<div class="mermaid{{ with .Get "class" }} {{ . }}{{ end }}">
%%{init: { 'theme': 'default' } }%%
{{ $data := replaceRE "(^\\s+```)" "" .Inner -}}
{{ replaceRE "(```\\s+$)" "" $data -}}
</div>
</div>
</div>
{{ with .Get "caption" }}<figcaption class="figure-caption"><center><em>{{ . | safeHTML }}</em></center></figcaption>{{ end }}
</figure>
{{ else -}}
{{ errorf "Failed to process mermaid shortcode: %s. Set mermaid to true in page front matter." .Position }}
{{ end -}} I'm using the child version of doks. To be able to use mermaid, I added the following mount. # config/_default/config.toml
[module]
[[module.mounts]]
source = "node_modules/mermaid"
target = "assets/mermaid" |
I'm no web expert by any means, but wouldn't setting |
Yes, presence of the |
Or, check on the local storage item set: var theme = (localStorage.getItem('theme') === 'dark') ? "dark" : "default"; |
Doks now uses the free Kroki service to render diagrams. See also Diagrams Unfortunately, Kroki does not "support" dark mode — yet. See also [Feature Request] Setting background color with a diagram option |
Summary
Add a Mermaid theme switch respecting the dark/light toggle. So, default Mermaid theme when toggled light, and dark Mermaid theme when toggled dark.
Basic example
See e.g. Drawing diagrams in Sanity with Mermaid.js.
Motivation
Better dark mode support.
The text was updated successfully, but these errors were encountered: