Expand description
§mmdr - Fast Mermaid Diagram Renderer
A pure Rust implementation of Mermaid diagram rendering, providing 100-600x faster rendering than mermaid-cli by eliminating browser dependencies.
§Quick Start
use mermaid_rs_renderer::{render, render_with_options, RenderOptions};
let diagram = r#"
flowchart LR
A[Start] --> B{Decision}
B -->|Yes| C[OK]
B -->|No| D[Cancel]
"#;
// Simple one-liner
let svg = render(diagram).unwrap();
// With options
let svg = render_with_options(diagram, RenderOptions::default()).unwrap();§Pipeline Control
For more control over the rendering pipeline, use the individual stages:
use mermaid_rs_renderer::{parse_mermaid, compute_layout, render_svg};
use mermaid_rs_renderer::{Theme, LayoutConfig};
let diagram = "flowchart LR; A-->B-->C";
// Stage 1: Parse
let parsed = parse_mermaid(diagram).unwrap();
// Stage 2: Layout
let theme = Theme::modern();
let config = LayoutConfig::default();
let layout = compute_layout(&parsed.graph, &theme, &config);
// Stage 3: Render
let svg = render_svg(&layout, &theme, &config);§Supported Diagram Types
- Flowcharts (
flowchart/graph): TD, TB, LR, RL, BT directions - Sequence Diagrams (
sequenceDiagram) - Class Diagrams (
classDiagram) - State Diagrams (
stateDiagram-v2) - ER Diagrams (
erDiagram) - Pie Charts (
pie) - XY Charts (
xychart) - Quadrant Charts (
quadrantChart) - Gantt (
gantt) - Timeline (
timeline) - Journey (
journey) - Mindmap (
mindmap) - Git Graph (
gitGraph)
§Features
- Pure Rust, no browser or Node.js required
- ~3ms cold start vs ~2500ms for mermaid-cli
- ~15MB memory vs ~300MB for mermaid-cli
- SVG and PNG output (PNG via resvg)
- Customizable themes and layout configuration
§Cargo Features
cli(default) - CLI binary support. Disable for library-only usage.png(default) - PNG output via resvg. Disable for SVG-only usage.
For minimal dependencies (e.g., embedding in other tools like Zola):
[dependencies]
mermaid-rs-renderer = { version = "0.1", default-features = false }Re-exports§
pub use config::Config;pub use config::LayoutConfig;pub use config::RenderConfig;pub use ir::DiagramKind;pub use ir::Direction;pub use ir::Edge;pub use ir::EdgeArrowhead;pub use ir::EdgeDecoration;pub use ir::EdgeStyle;pub use ir::Graph;pub use ir::Node;pub use ir::NodeLink;pub use ir::NodeShape;pub use ir::SequenceActivation;pub use ir::SequenceActivationKind;pub use ir::SequenceBox;pub use ir::StateNote;pub use ir::StateNotePosition;pub use ir::Subgraph;pub use layout::EdgeLayout;pub use layout::Layout;pub use layout::LayoutStageMetrics;pub use layout::NodeLayout;pub use layout::SubgraphLayout;pub use layout::compute_layout;pub use layout::compute_layout_with_metrics;pub use parser::ParseOutput;pub use parser::parse_mermaid;pub use render::write_output_png;pub use render::render_svg;pub use render::write_output_svg;pub use theme::Theme;pub use cli::run;
Modules§
Structs§
- Render
Detailed Result - Result of rendering with detailed layout stage timing information.
- Render
Options - Options for the high-level
renderfunction. - Render
Result - Result of rendering with timing information.
Functions§
- render
- Render a Mermaid diagram to SVG with default options.
- render_
with_ detailed_ timing - Render a Mermaid diagram to SVG with detailed timing information.
- render_
with_ options - Render a Mermaid diagram to SVG with custom options.
- render_
with_ timing - Render a Mermaid diagram to SVG with timing information.