Mermaid diagrams in Markdown
Example taken from mermaid.js.org ↗.
There are many diagramming languages (see text-to-diagram ↗). Mermaid ↗ seems to be popular, as it is supported by GitHub.
There are two options:
rehype-mermaid
- the original plugin. Battle-tested and well supported.@beoe/rehype-mermaid
- my experiment. It is based onmermaid-isomorphic
(the same one used byrehype-mermaid
). It also adds:- Selector-based dark mode ↗. Used by Starlight and others.
- Cache to prevent the permanent launch of a headless browser.
- Out-of-the-box compatibility with pan and zoom "plugin".
@beoe/rehype-mermaid
Installation
-
Install dependencies
-
Configure Astro. See note about Rehype Plugins for Code.
-
Add CSS for dark mode:
-
Optional install dependency for cache
-
Optional configure cache
-
Optional add pan and zoom for diagrams
rehype-mermaid
Installation
-
Install dependencies
-
Configure Astro. See note about Rehype Plugins for Code.
Strategies
inline-svg | img-svg | |
---|---|---|
Supports css ↗ option | ✔️ Yes | No |
Text is searchable (Cmd + F) | ✔️ Yes | No |
Supports dark ↗ mode (1) | No | ✔️ Yes |
Issues with rehype-raw ↗ (2) | Yes | ✔️ No |
Other CSS on the page may conflict (3) | Yes | ✔️ No |
inline-svg
is the default strategy.
(1) dark mode
To enable dark mode, use:
However, it doesn’t work with Starlight’s selector-based dark mode. See starlight#1829 ↗.
(2) issues with rehype-raw
I only noticed issues with the sankey
diagram, so this is a minor issue.
(3) other CSS
You can style inline SVG with CSS: