To convert Mermaid diagrams into DOT and SVG formats on Linux, here's a step-by-step approach using available CLI tools.
✅ Recommended Workflow
🎯 Goal:
Convert Mermaid (.mmd) → DOT (.dot) → SVG (.svg), or directly to SVG.
1. Use mmdc (Mermaid CLI) – for SVG
🔧 Installation
npm install -g @mermaid-js/mermaid-cli
🖼 Convert .mmd → .svg
mmdc -i input.mmd -o output.svg
2. Mermaid → DOT Conversion (not directly supported – workaround required)
Mermaid does not natively export to DOT format. If you must go via DOT for further processing with Graphviz, try:
A Pandoc filter: mermaid-filter
🔧 Install
pip install mermaid-filter
Requires: pandoc, mermaid-cli
🧪 Convert Mermaid to DOT with filtering (indirect: renders to SVG/PNG internally)
Mermaid diagrams internally rely on JS rendering, so exporting raw DOT from Mermaid is not officially supported.
If you really need DOT:
3. ✨ Alternative: Rewriting Mermaid to DOT manually
Since Mermaid and DOT describe similar structures (graphs, nodes, edges), you might:
- ● Use a parser like
mermaid2dot (unofficial, may not support all features)
- ● OR Convert manually, especially for simple diagrams.
Example Mermaid:
graph TD
A --> B
B --> C
Equivalent DOT:
digraph {
A -> B;
B -> C;
}
You can write a small script to convert basic Mermaid syntax to DOT format if needed.
4. Render DOT ➜ SVG (using Graphviz)
If you got .dot, you can convert to .svg using Graphviz:
dot -Tsvg input.dot -o output.svg
Summary Table
| From | To | Tool / Method |
|---|
.mmd | .svg | mmdc -i input.mmd -o output.svg |
.mmd | .dot | Manual / unofficial converters |
.dot | .svg | dot -Tsvg input.dot |
✅ Best Practice
- Use
mermaid-cli for direct .svg output.
- If
.dot is required for Graphviz, consider writing Mermaid in a DOT-like style and manually converting.
- For automation, consider scripting basic conversion rules.
Let me know the specific type of Mermaid diagram you want to convert — I can help convert that example to DOT!