Skip to main content

Crate mermaid_svg

Crate mermaid_svg 

Source
Expand description

Render Mermaid diagrams to SVG in pure Rust.

Supported diagram types: pie, sequence, flowchart, state, class, ER, gantt, journey, timeline, sankey, quadrantChart, xychart, radar, packet, mindmap, gitGraph, requirementDiagram, C4 (Context/Container/Component/ Dynamic/Deployment), block, architecture, kanban, treemap, zenuml.

let svg = mermaid_svg::render("pie\n\"A\" : 1\n\"B\" : 2\n").unwrap();
assert!(svg.starts_with("<svg"));

Reference output for every supported diagram type, rendered by this crate from the sources in samples/ (regenerate with cargo run --example gen-doc-diagrams).

§Pie

Pie diagram ## Sequence Sequence diagram ## Flowchart Flowchart diagram ## State State diagram ## Class Class diagram ## Entity relationship Entity relationship diagram ## Gantt Gantt diagram ## User journey User journey diagram ## Timeline Timeline diagram ## Sankey Sankey diagram ## Quadrant Quadrant diagram ## XY chart XY chart diagram ## Radar Radar diagram ## Packet Packet diagram ## Mindmap Mindmap diagram ## Git graph Git graph diagram ## Requirement Requirement diagram ## C4 C4 diagram ## Block Block diagram ## Architecture Architecture diagram ## Kanban Kanban diagram ## Treemap Treemap diagram ## ZenUML ZenUML diagram

Modules§

ast
AST types shared by all diagram kinds.

Structs§

DiagramMeta
Shared, diagram-agnostic metadata extracted from the source preamble (YAML frontmatter, %%{init}%% directives, and accTitle/accDescr statements) before dispatching to a per-diagram parser.
Theme

Enums§

Diagram
ParseError
RenderError
SyntaxKind
The class of a ParseError::Syntax failure. Lets callers distinguish the recurring kinds of parse error (unknown statement vs bad number vs unclosed block) without inspecting the free-form message.

Functions§

parse
parse_with_meta
Parse input, also returning the cross-cutting DiagramMeta (title, accTitle/accDescr, theme) extracted from the source preamble. The diagram body is parsed from the source with the preamble removed.
render
render_diagram
render_diagram_with
render_with