Mermaid Diagrams
Convert graphs to and from Mermaid diagram-as-code format. Supports 7 diagram types.Features
- 7 diagram types: Flowchart, sequence, state, class, ER, mindmap, block
- No dependencies: Pure JavaScript conversion
- Diagram-specific: Each type has specialized node/edge data
- Round-trip safe: Preserves diagram-specific features
Import
Flowchart Diagrams
toMermaidFlowchart()
Converts a graph to a Mermaid flowchart.
Shape Support
| Graph Shape | Mermaid Syntax | Description |
|---|---|---|
rectangle | [text] | Rectangle (default) |
rounded | (text) | Rounded rectangle |
circle | ((text)) | Circle |
double-circle | (((text))) | Double circle |
stadium | ([text]) | Stadium (pill) |
cylinder | [(text)] | Cylinder/database |
diamond | {text} | Diamond/decision |
hexagon | {{text}} | Hexagon |
parallelogram | [/text/] | Parallelogram |
trapezoid | [/text\] | Trapezoid |
asymmetric | >text] | Asymmetric/flag |
subroutine | [[text]] | Subroutine |
Edge Styles
Subgraphs (Compound Graphs)
fromMermaidFlowchart()
Sequence Diagrams
toMermaidSequence()
Actor Types
Arrow Types
| Stroke | Arrow Type | Mermaid | Description |
|---|---|---|---|
solid | filled | ->> | Solid arrow |
solid | open | -> | Solid line, open arrow |
solid | cross | -x | Solid line, cross |
solid | async | -) | Async message |
dotted | filled | -->> | Dotted arrow |
dotted | open | --> | Dotted line, open arrow |
dotted | cross | --x | Dotted line, cross |
dotted | async | --) | Dotted async |
Control Flow Blocks
loop, alt, opt, par, critical, break, rect
fromMermaidSequence()
State Diagrams
toMermaidState() / fromMermaidState()
- Initial state markers
- Final states
- Composite states (via
parentId) - Choice nodes
- Fork/join
Class Diagrams
toMermaidClass() / fromMermaidClass()
inheritance, composition, aggregation, association, link, dependency, realization
ER Diagrams
toMermaidER() / fromMermaidER()
zero-or-one, exactly-one, zero-or-more, one-or-more
Mindmap Diagrams
toMermaidMindmap() / fromMermaidMindmap()
parentId for tree structure, not edges.
Block Diagrams
toMermaidBlock() / fromMermaidBlock()
Rendering Mermaid
In Markdown
Programmatically
Type Definitions
See Also
- DOT Format - Another diagram-as-code format
- Format Overview - All supported formats
- Mermaid Documentation - Official Mermaid docs