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

Mermaid config doesn't work. #1850

Open
Erifirin opened this issue Sep 2, 2024 · 3 comments
Open

Mermaid config doesn't work. #1850

Erifirin opened this issue Sep 2, 2024 · 3 comments

Comments

@Erifirin
Copy link

Erifirin commented Sep 2, 2024

I tried to change mermaid theme as it described in documentation: https://sli.dev/custom/config-mermaid. I created a file ./setup/mermaid.ts and copied example into it. But it didn't change anything and mermaid still uses the default theme. However, custom theme variables work properly if mermaid.ts is changed while slidev is running. After restarting slidev, mermaid reverts back to default theme.

Minimal reproduction

Steps to reproduce the behavior:

  1. Create ./setup/mermaid.ts with content from example https://sli.dev/custom/config-mermaid#custom-theme-styles;
  2. Run slidev;
  3. Go to slide with mermaid graph/flowchart.

Environment

  • Slidev: 0.49.27, 0.49.29
  • Browser: chrome 128
  • OS: win 10
@KermanX
Copy link
Member

KermanX commented Sep 2, 2024

possibly #1830

@Erifirin
Copy link
Author

Erifirin commented Sep 3, 2024

No, I have one instance of slidev running from terminal. Moreover, I've faced the same behavior on macos.

os: macos 14.6.1 (M1, 2020)
browser: safari
node: 22.7.0
slidev: 0.49.29

Here's what I do:

  1. mkdir slides
  2. cd slides
  3. npm init slidev@latest
    Project name: test
    Install and start it now?: yes
    Choose the package manager: npm
  4. Wait for presentation to open. Go to slide 12.
  5. Create ./setup/mermaid.ts with following (taken from mermaid examples)
import { defineMermaidSetup } from '@slidev/types'

export default defineMermaidSetup(() => {
  return {
    theme: 'base',
    themeVariables: {
      primaryColor: '#BB2528',
      primaryTextColor: '#fff',
      primaryBorderColor: '#7C0000',
      lineColor: '#F8B229',
      secondaryColor: '#006100',
      tertiaryColor: '#fff'
    }
  }
})
  1. Go back to the slides. Nothing has changed.
    image

  2. Ok. Return to terminal with slidev and press r to restart.

  3. In browser go to slide 12 again. Nothing has changed.

  4. Make any minor edits to the file ./setup/mermaid.ts and save.

  5. Go to slide 12. Wow! All the arrows turned yellow, but rest remained the same:
    image

  6. Now let's stop slidev by pressing q.

  7. And start it again:
    cd test
    npm exec slidev

  8. Go to slide 12 and it again uses default theme:
    image

In result, the only working way to change the mermaid theme is to write themeVariables in each mermaid block. It works perfect but very inconvenient.

%%{
  init: {
    'theme': 'base',
    'themeVariables': {
      'primaryColor': '#BB2528',
      'primaryTextColor': '#fff',
      'primaryBorderColor': '#7C0000',
      'lineColor': '#F8B229',
      'secondaryColor': '#006100',
      'tertiaryColor': '#fff'
    }
  }
}%%

image

@Erifirin
Copy link
Author

Erifirin commented Sep 6, 2024

@KermanX It seems I've managed to resolve it.
It's necessary to force empty a browser cache after creating file ./setup/mermaid.ts. Now defineMermaidSetup() method is called every time the slidev is launched. As a result, the colors of the diagrams change, although not completely. In light theme everything works well, but in dark theme only part of themeVariables are applied :)

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants