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

Support YAML frontmatter configuration #147

Closed
kdeldycke opened this issue Aug 13, 2024 · 3 comments · Fixed by #151
Closed

Support YAML frontmatter configuration #147

kdeldycke opened this issue Aug 13, 2024 · 3 comments · Fixed by #151

Comments

@kdeldycke
Copy link
Contributor

Each mermaid diagram can be prefixed with a frontmatter configuration block to alter its default rendering. Example:

---
title: Hello Title
config:
  theme: base
  themeVariables:
    primaryColor: "#00ff00"
---
flowchart
	Hello --> World

This is the preferred way starting with Mermaid v10.5.0+ since %%{``}%% directives are now deprecated.

Unfortunately this syntax is not supported by sphinxcontrib-mermaid.

How to reproduce

Add the following diagram to any markdown file:

```mermaid
---
title: Hello Title
config:
  theme: base
  themeVariables:
    primaryColor: "#00ff00"
---
flowchart
	Hello --> World
```

It gets rendered with its default style:
Screenshot 2024-08-13 at 16 57 23

Instead, I expect it to be rendered the same way it is displayed in the official documentation:
Screenshot 2024-08-13 at 16 58 08

This issue was produced in the following environment:

  • Sphinx 7.3.7
  • sphinxcontrib-mermaid 0.9.2
  • myst-parser 3.0.1
  • Python 3.12.4
@kdeldycke
Copy link
Contributor Author

Note that GitHub is supporting these frontmatter configuration directives:

---
title: Hello Title
config:
  theme: base
  themeVariables:
    primaryColor: "#00ff00"
---
flowchart
	Hello --> World
Loading

@kdeldycke kdeldycke changed the title Support per-diagram YAML frontmatter configuration SupportYAML frontmatter configuration Aug 13, 2024
@kdeldycke kdeldycke changed the title SupportYAML frontmatter configuration Support YAML frontmatter configuration Aug 13, 2024
kdeldycke added a commit to kdeldycke/click-extra that referenced this issue Aug 13, 2024
kdeldycke added a commit to kdeldycke/meta-package-manager that referenced this issue Aug 13, 2024
@kdeldycke
Copy link
Contributor Author

My particular use-case for this was to deactivate the rendering of values in a Sankey diagram like this:

---
config:
  sankey:
    showValues: false
---
sankey-beta

Agricultural 'waste',Bio-conversion,124.729
Bio-conversion,Liquid,0.597
Bio-conversion,Losses,26.862
Bio-conversion,Solid,280.322
Bio-conversion,Gas,81.144

As a temporary workaround, I deactivated globally value rendering for all Sankey diagrams by tweaking the Mermaid initialization in my Sphinx's conf.py configuration file:

mermaid_version = "latest"
mermaid_init_js = """
  const config = {
    startOnLoad: true,
    sankey: {
      showValues: false,
    },
  };
  mermaid.initialize(config);
"""

@mgaitan
Copy link
Owner

mgaitan commented Aug 14, 2024

@kdeldycke are you interested in opening a PR for this? It seems a very valuable feature.

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

Successfully merging a pull request may close this issue.

2 participants