Render Mermaid Diagrams from Markdown
Render Mermaid Diagrams from Markdown
Mermaid turns text into diagrams. Because the diagram source remains in the Markdown file, it can be reviewed in Git and edited without a separate drawing format.
Create a flowchart
Add a fenced code block whose language is mermaid:
```mermaid
flowchart LR
Draft --> Review
Review --> Publish
Review --> Revise
Revise --> Draft
```Markdown Explorer recognizes the language and renders the diagram in the editor or Preview.
Edit the source
Keep Split View open when the diagram is unfamiliar. The left pane shows the Mermaid syntax while the right pane shows the rendered result. In supported editor surfaces, switch a rendered Mermaid block back to code editing to make changes.
A sequence example
```mermaid
sequenceDiagram
participant Writer
participant Reviewer
Writer->>Reviewer: Open pull request
Reviewer-->>Writer: Request changes
Writer->>Reviewer: Push revision
Reviewer-->>Writer: Approve
```Use short node labels first. Very long labels make diagrams difficult to scan on a narrow Preview pane.
Troubleshooting
If the diagram does not render:
- Confirm the opening fence says
mermaid. - Confirm the closing triple backticks are present.
- Reduce the source to two nodes and one connection.
- Check node IDs and arrow syntax.
- Add the remaining branches one at a time.
The native application bundles a Mermaid runtime, while the web renderer uses the application’s web integration. A syntax error should affect the diagram, not rewrite the Markdown source.
Mermaid is best for architecture, flow, sequence, state, and relationship diagrams whose text representation is valuable. Use an image when hand-drawn visual details matter more than diffable source.
For formulas rather than relationships, see LaTeX math with KaTeX Preview.