mermaid

package
v1.111.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

Mermaid support

Docker Agent parses supported Mermaid syntax in this package and renders it for the terminal through pkg/tui/components/mermaid. Unsupported or unparseable Mermaid blocks remain syntax-highlighted code blocks.

Diagram support

Mermaid diagram Parse Render Support level
graph / flowchart Partial
sequenceDiagram Partial
stateDiagram / stateDiagram-v2 Partial
classDiagram Falls back to code
erDiagram Falls back to code
journey Falls back to code
gantt Falls back to code
pie Falls back to code
quadrantChart Falls back to code
requirementDiagram Falls back to code
gitGraph Falls back to code
mindmap Falls back to code
timeline Falls back to code
sankey-beta Falls back to code
xychart-beta Falls back to code
block-beta Falls back to code
packet-beta Falls back to code
kanban Falls back to code
architecture-beta Falls back to code
C4 diagrams Falls back to code

Flowcharts

Feature Parse Render Notes
graph and flowchart headers Both are accepted
TD, TB, BT, LR, RL direction ⚠️ Retained in the parsed document; terminal rendering is currently top-down
Node declarations and references Explicit and implicit nodes
Quoted labels Includes semicolons inside labels
Chained edges For example, A --> B --> C
`--> label ` edge labels
-- label --> edge labels
Cycles and shared targets Rendered using reference nodes
Rectangle nodes [text]
Rounded nodes (text) ⚠️ Parsed; currently rendered as a box
Stadium nodes ([text]) ⚠️ Parsed; currently rendered as a box
Subroutine nodes [[text]] ⚠️ Parsed; currently rendered as a box
Cylinder nodes [(text)] ⚠️ Parsed; currently rendered as a box
Circle nodes ((text)) ⚠️ Parsed; currently rendered as a box
Decision nodes {text} Marked distinctly with
Hexagon nodes {{text}} ⚠️ Parsed; currently rendered as a box
Edge line and arrow styles ⚠️ Accepted operators are normalized to terminal connectors
subgraph ⚠️ Directive is skipped; contained nodes may still render
classDef, class, style ⚠️ Skipped
click links ⚠️ Skipped
linkStyle ⚠️ Skipped

Sequence diagrams

Feature Parse Render Notes
participant
actor ⚠️ Rendered as a participant box, not a stick figure
as aliases For example, participant C as Client
Forward messages
Return messages Correct left/right direction
Dashed versus solid arrows ⚠️ Syntax is accepted, but visual style is normalized
Self-messages
Note over A,B
Note left of A
Note right of A
Notes in timeline order
Apostrophes in text For example, client's SYN
autonumber Ignored
activate / deactivate Ignored
alt / else / end Control frame omitted; contained messages may still render
loop Frame omitted
opt Frame omitted
par / and Frame omitted
critical / option Frame omitted
break Frame omitted
Participant creation and destruction
Links and participant menus

State diagrams

Feature Parse Render Notes
stateDiagram
stateDiagram-v2
Simple transitions
Transition labels For example, Idle --> Running: start
Named state declarations For example, state "Processing" as Working
Start state [*] --> State Rendered as Start
End state State --> [*] Rendered as End
Cyclic transitions
Composite and nested states
Concurrent states
State notes
Choice, fork, and join pseudostates
State direction declarations
Styling and classes

Documentation

Overview

Package mermaid parses supported Mermaid diagram syntax into a reusable document model.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUnsupportedDiagram indicates that the Mermaid diagram grammar is not supported.
	ErrUnsupportedDiagram = errors.New("unsupported Mermaid diagram")
	// ErrInvalidDiagram indicates that no renderable syntax could be parsed.
	ErrInvalidDiagram = errors.New("invalid Mermaid diagram")
)
View Source
var EdgeOperators = [...]string{"-.->", "-->>", "-->", "==>", "---", "->>", "--x", "--o", "->"}

Functions

This section is empty.

Types

type DiagramKind

type DiagramKind uint8

DiagramKind identifies a Mermaid diagram grammar.

const (
	// DiagramUnknown represents an unsupported diagram grammar.
	DiagramUnknown DiagramKind = iota
	// DiagramFlowchart represents graph and flowchart diagrams.
	DiagramFlowchart
	// DiagramSequence represents sequence diagrams.
	DiagramSequence
	// DiagramState represents state diagrams.
	DiagramState
)

type Document

type Document struct {
	Kind           DiagramKind
	Direction      string
	Nodes          map[string]Node
	NodeOrder      []string
	Edges          []Edge
	Participants   []string
	SequenceEvents []SequenceEvent
}

Document is the syntax model produced by Parse.

func Parse

func Parse(source string) (Document, error)

Parse parses a supported Mermaid diagram into a document model.

type Edge

type Edge struct {
	From  string
	To    string
	Label string
}

Edge connects two nodes and optionally carries a display label.

type Node

type Node struct {
	ID    string
	Label string
	Shape NodeShape
}

Node is a declared or implicitly referenced diagram node.

type NodeShape

type NodeShape uint8

NodeShape identifies the visual shape declared for a node.

const (
	ShapeDefault NodeShape = iota
	ShapeRectangle
	ShapeRounded
	ShapeStadium
	ShapeSubroutine
	ShapeCylinder
	ShapeCircle
	ShapeDecision
	ShapeHexagon
)

type NotePlacement

type NotePlacement uint8

NotePlacement identifies where a sequence note is anchored.

const (
	NoteOver NotePlacement = iota
	NoteLeftOf
	NoteRightOf
)

type SequenceEvent

type SequenceEvent struct {
	Kind      SequenceEventKind
	From      string
	To        string
	Label     string
	Placement NotePlacement
}

SequenceEvent is a message or note in timeline order.

type SequenceEventKind

type SequenceEventKind uint8

SequenceEventKind identifies an item on a sequence-diagram timeline.

const (
	SequenceMessage SequenceEventKind = iota
	SequenceNote
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL