Mermaid diagrams in markdown
Example taken from mermaid.js.org
There are a lot of diagraming languages (see text-to-diagram). Mermaid seems to be popular (it is supported by GitHub).
There are two options:
rehype-mermaid
- original plugin. Battle tested and well supported@beoe/rehype-mermaid
- my experiment. It is based onmermaid-isomorphic
(the same one used byrehype-mermaid
). But it also adds:- Selector based dark mode. Used by Starlight and others
- cache - to prevent permanent launch of headless browser
- out of the box compatible 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 deafault strategy.
(1) dark mode
In order to enable dark mode use:
But it doesn’t work with Starlight’s slector based dark mode. See starlight#1829.
(2) issues with rehype-raw
I noticed issues only with sankey
diagram. So this is minor issue
(3) other CSS
You may style inline SVG with CSS: