Skip to main content

Crate merman

Crate merman 

Source
Expand description

Headless, parity-focused Mermaid parsing and rendering in Rust.

merman is the public Rust facade for the project. It re-exports merman_core for detection, parsing, metadata, semantic JSON, and typed render models, then adds optional convenience modules for SVG, raster, and terminal text output.

The compatibility target is Mermaid @11.15.0. Upstream Mermaid behavior is treated as the specification, including cases where the browser implementation is surprising. The root README and docs/alignment/STATUS.md document the current parity matrix, deferred residuals, and release gates.

§Choosing an API

GoalFeatureStart with
Parse Mermaid or produce semantic JSONnoneEngine and ParseOptions
Render Mermaid-like SVGrendermerman::render::HeadlessRenderer
Prepare SVG for usvg / resvg / raster exportrenderHeadlessRenderer::render_svg_resvg_safe_sync
Render terminal-friendly textasciimerman::ascii::HeadlessAsciiRenderer
Render PNG, JPG, or PDF from RustrasterHeadlessRenderer::render_png_sync and render::raster::RasterOptions

If you already know the diagram type, use the *_with_type_sync methods on Engine to skip detection. If you need lower-level layout or SVG pipeline control, use the re-exported types under merman::render or depend on merman-render directly.

§Features

  • render: layout plus SVG rendering through merman::render.
  • ascii: ASCII/Unicode text rendering through merman::ascii.
  • raster: PNG/JPG/PDF output through merman::render::raster; this implies render.
  • ratex-math: pure-Rust math label rendering for the SVG path; this implies render.

The default feature set is intentionally empty so parser-only users do not pull in layout, SVG, raster, or text-output dependencies.

§SVG quickstart

use merman::render::HeadlessRenderer;

let renderer = HeadlessRenderer::new().with_diagram_id("readme-example");
let svg = renderer
    .render_svg_sync("flowchart TD\nA[Start] --> B[Done]")?
    .expect("diagram detected");

println!("{svg}");

A fresh HeadlessRenderer keeps the Mermaid parity SVG contract for HeadlessRenderer::render_svg_sync. Calling with_host_theme or with_svg_pipeline installs a renderer-owned output pipeline for that method. Use HeadlessRenderer::render_svg_readable_sync when browser <foreignObject> labels may need readable <text> fallbacks, and HeadlessRenderer::render_svg_resvg_safe_sync when the output will be consumed by usvg, resvg, or the built-in raster helpers.

§ASCII quickstart

use merman::ascii::{AsciiRenderOptions, HeadlessAsciiRenderer};

let renderer = HeadlessAsciiRenderer::new()
    .with_strict_parsing()
    .with_ascii_options(AsciiRenderOptions::unicode());
let text = renderer
    .render_ascii_sync("sequenceDiagram\nA->>B: Hello")?
    .expect("diagram detected");

println!("{text}");

Text output is intentionally terminal-native rather than SVG-derived. The currently supported public subset covers flowchart/graph, sequenceDiagram, classDiagram, erDiagram, and xychart.

§Raster output

The raster feature renders SVG through the resvg-safe pipeline before conversion. PNG and JPG use a default pixmap budget to avoid accidental huge allocations from very large Mermaid viewBox values. For UI previews, pass a visible target box through RasterOptions::with_fit_to and use RasterOptions::with_scale for device-pixel ratio.

Modules§

ascii
baseline
Active upstream Mermaid baseline metadata.
common
common_db
config
detect
diagram
diagrams
entities
error
generated
geom
models
preprocess
render
sanitize
time
utils

Structs§

Detector
One diagram detector entry.
DetectorRegistry
Ordered registry that detects Mermaid diagram types.
DiagramRegistry
Registry for semantic JSON parsers keyed by Mermaid diagram type id.
Engine
Headless Mermaid parser engine.
MermaidConfig
ParseMetadata
Metadata extracted before semantic diagram parsing.
ParseOptions
Parser behavior switches shared by metadata, semantic JSON, and typed render-model parsing.
ParsedDiagram
Parsed diagram metadata plus the Mermaid-compatible semantic JSON model.
ParsedDiagramRender
Parsed diagram metadata plus a typed render model.
PreprocessResult
RenderDiagramRegistry
Registry for typed render-model parsers keyed by Mermaid diagram type id.

Enums§

Error
RenderSemanticModel
Typed semantic model used by the headless renderer.

Constants§

MAX_DIAGRAM_NESTING_DEPTH
Maximum nested diagram/include depth accepted by recursive parsers.

Functions§

preprocess_diagram
preprocess_diagram_with_known_type
supported_diagrams
Returns supported diagram metadata names for binding and host capability discovery.
supported_host_theme_presets
Returns built-in host/editor theme preset names.
supported_themes
Returns Mermaid theme names supported by the pinned baseline.

Type Aliases§

DiagramSemanticParser
Parser used by the semantic JSON path for one Mermaid diagram family.
RenderSemanticParser
Parser used by the typed render-model path for one Mermaid diagram family.
Result