Skip to content
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

Allow different mermaid theme on dark mode #1043

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

BernatBC
Copy link
Member

Issue

Description

Before this PR, one could define a theme for mermaid. However, the defined theme was set for both light and dark theme.

This PR adds support for defining a custom theme for both light and dark site themes. There are 2 ways to define them:

  1. Globally (config.yaml/hugo.yaml):
    # Enable this to create flowcharts using shortcodes.
    flowchart:
      enable: true
      services:
        mermaid:
          theme: default  # Can be: default, dark, forest, neutral
          darkTheme: dark
  1. Per diagram:
{{< mermaid align="center" >}}
%%{init: {'theme':'forest', 'darktheme':'forest'}}%%
[diagram]
{{< /mermaid >}}

Test Evidence

When defining a diagram using the forest theme for both light and dark theme (first diagram), and a diagram using the default theme (second diagram):

{{< mermaid align="center" >}}
%%{init: {'theme':'forest', 'darktheme':'forest'}}%%
graph LR;
    A[Hard edge] -->|Link text| B(Round edge)
    B --> C{Decision}
    C -->|One| D[Result one]
    C -->|Two| E[Result two]
{{< /mermaid >}}

{{< mermaid align="center" >}}
graph LR;
    A[Hard edge] -->|Link text| B(Round edge)
    B --> C{Decision}
    C -->|One| D[Result one]
    C -->|Two| E[Result two]
{{< /mermaid >}}

Site on light theme:
Screenshot From 2025-03-24 18-56-43

Site on dark theme:
Screenshot From 2025-03-24 18-56-29

Copy link

netlify bot commented Mar 24, 2025

Deploy Preview for toha-ci ready!

Name Link
🔨 Latest commit 4ae3d00
🔍 Latest deploy log https://app.netlify.com/sites/toha-ci/deploys/67e41bb3f368bf0008550101
😎 Deploy Preview https://deploy-preview-1043--toha-ci.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

elements.forEach(element => {
if (element.getAttribute('data-original-code') != null) {
element.removeAttribute('data-processed');
element.innerHTML = element.getAttribute('data-original-code');

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.
@BernatBC BernatBC requested a review from hossainemruz March 24, 2025 18:17
Copy link
Member

@hossainemruz hossainemruz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank @BernatBC ! Look like mermaid is broken in the deployment preview. Can you please fix it?

image

@BernatBC BernatBC marked this pull request as draft March 26, 2025 15:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Set mermaid dark theme automatically
2 participants