Documentation
¶
Overview ¶
Package mermaid2d2 converts between Mermaid and D2 diagram syntax.
Conversion is source-to-source in both directions and driven by two functions: MermaidToD2 and D2ToMermaid. Neither renders anything; the output is diagram source for the other tool to lay out.
Mermaid flowchart, sequenceDiagram, stateDiagram-v2, classDiagram, erDiagram, mindmap, and the C4 family convert to D2. Diagram types with no D2 graph analog (gantt, pie, journey, xychart, gitGraph) return an error rather than a mangled approximation.
The reverse direction infers the Mermaid diagram type from the D2 shapes present: sql_table shapes become an erDiagram, class shapes a classDiagram, and anything else a flowchart.
Both directions are lossy where the formats disagree, and each function documents what it drops.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func D2ToMermaid ¶
D2ToMermaid parses D2 source and emits the Mermaid diagram it maps to.
The Mermaid diagram type is inferred from the shapes present: sql_table shapes emit an erDiagram, class shapes emit a classDiagram, and anything else emits a flowchart (containers become subgraphs, connections become edges, classes:/class: styling becomes classDef/class, and the board direction sets orientation). A graph that mixes sql_table or class shapes with each other or with plain nodes/containers has no single Mermaid diagram type and returns an error. D2 features with no Mermaid equivalent in the chosen diagram type (grids, and — outside flowcharts — arrows, styling, containers) are dropped.
func MermaidToD2 ¶
MermaidToD2 parses Mermaid source and emits equivalent D2.
Flowchart nodes, edges, and subgraphs map onto D2 shapes, connections, and containers; sequence diagrams map onto a D2 sequence_diagram, with loop/alt/ opt blocks becoming labeled groups; state diagrams map onto nodes and connections, with composite states becoming containers; class diagrams map onto D2 class shapes, with relationships becoming connections whose arrowheads encode the UML relation type; ER diagrams map onto D2 sql_table shapes, with attributes as typed columns and relationships as connections; mindmaps map onto a D2 tree of nodes connected to their parents; C4 diagrams (Context, Container, Component, Dynamic, Deployment) map onto D2 nodes and containers, with Rel(...) relationships becoming connections. Diagram types with no D2 equivalent (gantt, pie, journey, ...) return an error rather than being mangled. Sequence notes become D2 notes; state and class notes render as a tooltip attribute on their target node.
Types ¶
This section is empty.