Expand description
Mermaid parsing and rendering through one operation-scoped facade.
Renderer owns long-lived engine defaults. Each RenderRequest describes one source,
target, resource policy, and OperationControl. The request is executed synchronously by
Renderer::render; SVG, ASCII, and binary output remain target-local adapters behind the
same operation boundary.
The facade deliberately does not expose source-to-SVG or source-to-ASCII convenience functions. Keeping the target and its policy in a typed request makes cancellation, deadlines, resource budgets, and output ownership explicit at every call site.
§Choosing an API
| Goal | Feature | Start with |
|---|---|---|
| Parse Mermaid or produce semantic JSON | diagram-* selectors, without defaults | Engine and ParseOptions |
| Analyze diagnostics or Markdown fences | analysis | analysis::Analyzer |
| Build parser-backed editor snapshots | editor | editor::analyze_document_snapshot_with_shared_text |
| Render Mermaid-like SVG | svg | Renderer and RenderRequest::svg |
| Render terminal-friendly text | ascii | Renderer and RenderRequest::ascii |
| Render PNG from Rust | png | Renderer and RenderRequest::png |
| Render JPEG from Rust | jpeg | Renderer and RenderRequest::jpeg |
| Render a vector PDF from Rust | pdf | Renderer and RenderRequest::pdf |
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::svg or depend on
merman-render directly.
§Features
-
diagram-*: compile the selected logical families and their typed models.all-diagramsselects every built-in family; these selectors do not enable outputs or engines. -
analysis: render-free diagnostics, source mapping, and Markdown analysis throughmerman::analysis. -
editor: parser-backed editor snapshots and queries throughmerman::editor; this impliesanalysis. -
svg: layout plus SVG rendering throughmerman::svg. -
ascii: ASCII/Unicode text rendering throughmerman::ascii. -
png,jpeg, andpdf: bounded binary export throughmerman::svg::export; each impliessvgbut does not imply either of the other binary formats. -
math: pure-Rust math label rendering for the SVG path; this impliessvg.
The default feature set combines all-diagrams with complete-svg-elk: it supports
all built-in parsers, Mermaid 12’s default ELK SVG path, deterministic rendering, the Cytoscape
layout engine, and math labels without ambient system adapters. Distributed artifacts must
retain the ELK implementation’s EPL-2.0 notices and source provenance. Use default-features = false
with explicit family selectors and complete-svg to omit ELK, or choose individual
capability leaves when you need a measured artifact closure. Neither SVG aggregate selects families.
Parser-only applications should depend on merman-core directly. If they need this facade’s
re-exports instead, set default-features = false and select the required diagram-* features
(or all-diagrams to retain the previous parser surface). An ordinary merman dependency
intentionally compiles the complete SVG workflow.
§Quick start
use merman::{OperationControl, RenderOutput, RenderRequest, Renderer, SvgRequest};
let output = Renderer::new().render(RenderRequest::svg(
"flowchart TD\nA[Start] --> B[Done]",
OperationControl::new(),
SvgRequest::default(),
))?;
let RenderOutput::Svg(Some(svg)) = output else {
return Err("source did not contain a Mermaid diagram".into());
};
println!("{}", svg.svg());For semantic inspection, use Renderer::prepare_semantic or a
RenderTarget::Semantic request. For terminal output, use RenderTarget::Ascii. The
target adapters never create a replacement operation or silently replace the caller’s
cancellation handle.
§Rendering lifecycle
Merman keeps parsing, semantic preparation, target selection, and output ownership inside one operation boundary.
Re-exports§
pub use diagnostic::TerminalDiagnostic;pub use diagnostic::TerminalDiagnosticDetails;pub use diagnostic::TerminalRuntimePolicyError;pub use render::AsciiRequest;pub use render::JpegRequest;pub use render::PngRequest;pub use render::RasterOutput;pub use render::OperationExecutionPath;pub use render::RenderEvidence;pub use render::SvgEnvironment;pub use render::SvgLayoutOutput;pub use render::SvgOutput;pub use render::SvgRequest;pub use render::PdfOutput;pub use render::PdfRequest;pub use render::RenderError;pub use render::RenderOutput;pub use render::RenderRequest;pub use render::RenderTarget;pub use render::Renderer;pub use render::ResourceLimitCause;pub use render::ResourceLimitExceeded;pub use render::SemanticArtifact;pub use merman_analysis as analysis;pub use merman_editor_core as editor;
Modules§
- ascii
- ASCII target-local types and model-level backend interface. ASCII target-local types, capabilities, and terminal-safe diagnostic projection.
- baseline
- Active upstream Mermaid baseline metadata.
- common
- common_
db - config
- detect
- diagnostic
- Target-neutral, terminal-safe projection for parser and runtime-policy diagnostics.
- diagram
- diagrams
- Public data models for Mermaid diagram families.
- entities
- error
- generated
- geom
- models
- operation
- Target-neutral lifecycle primitives for CPU-bound Merman operations.
- preprocess
- render
- Operation boundary
- resources
- Backend-independent Mermaid source and semantic-model resource policy.
- runtime
- sanitize
- svg
- SVG target-local types and backend capabilities. SVG target-local adapters and host-service types.
- svg_
security - theme_
color - Source-backed color operations used by Mermaid themes and renderers.
- time
- utils
Structs§
- Built
InTyped Render Family - Canonical public identity for one compiled concrete built-in typed render family.
- Captured
Panic - Non-cancellation result of one editor snapshot capture operation.
- Custom
Json Render Model - Explicit non-built-in JSON model boundary for custom parser adapters.
- Detector
- One diagram detector entry.
- Detector
Registry - Ordered registry that detects Mermaid diagram types.
- Diagram
Family Capability - Diagram
Family Id - Closed, catalog-owned identity for one logical Mermaid diagram family.
- Diagram
Family Selector - Public Cargo selector for one logical family, regardless of this build’s availability.
- Diagram
Header Fact - Diagram
Parse Snapshot - One preprocessing, detection, and family-construction operation for editor consumers.
- Diagram
Registry - Registry for semantic JSON parsers keyed by Mermaid diagram type id.
- Diagram
Warning Fact - Shared warning fact emitted by diagram families for analysis and lint consumers.
- Editor
Expected Syntax - Parser-produced cursor context hint for completion and other editor features.
- Editor
Family Semantics - Typed family semantics consumed by editor projections.
- Editor
Semantic Diagnostic - Parser-backed diagnostic emitted while producing editor-visible semantic facts.
- Editor
Semantic Facts - Parser-produced facts used by lint, completion, and LSP without exposing a public AST.
- Editor
Semantic Symbol - A parser-produced symbol occurrence.
- Engine
- Headless Mermaid parser engine.
- Mermaid
Config - Operation
Cancelled - Structured cooperative cancellation returned by an operation checkpoint.
- Operation
Control - Cloneable operation-scoped cooperative cancellation and deadline control.
- Operation
Resource Limit Exceeded - Target-neutral description of a checked operation resource rejection.
- Operation
Resource Override - One explicit policy override captured when a resource terminal is first recorded.
- Operation
Resource Provenance - Immutable policy provenance attached to the first operation resource terminal.
- Parse
Diagnostic - Structured parser diagnostic carried by
Error::DiagramParse. - Parse
Metadata - Metadata extracted before semantic diagram parsing.
- Parse
Options - Parser behavior switches for model-producing parse facades.
- Parsed
Diagram - Parsed diagram metadata plus the Mermaid-compatible semantic JSON model.
- Parsed
Diagram Render - Parsed diagram metadata plus its canonically paired typed render model.
- Preprocess
Result - Preprocessed
Source - Parser text together with an exact, composable map back to the caller’s source.
- Render
Diagram Registry - Registry for typed render-model parsers keyed by Mermaid diagram type id.
- Source
Span - Byte span attached to an editor-visible semantic fact.
Enums§
- Cancel
Reason - Why an operation stopped at a cooperative checkpoint.
- Custom
Json Provenance - Origin of a custom JSON render model.
- Diagram
Parse Outcome - Semantic result retained by one editor-facing diagram parse operation.
- Diagram
Snapshot Capture - Editor
Expected Syntax Kind - Parser-known syntax category that is expected at a source span.
- Editor
Rename Policy - Parser-owned validation policy for renaming an entity occurrence.
- Editor
Semantic Completeness - Whether editor-facing facts came from a complete family parse or a recoverable partial parse.
- Editor
Semantic Diagnostic Kind - Editor
Semantic Kind - Protocol-independent symbol classification for editor-facing consumers.
- Editor
Semantic Role - How downstream editor indexes should project a parser-produced symbol.
- Error
- Operation
Ledger Error - Sticky terminal failure shared by operation controls and target-owned resource adapters.
- Operation
Phase - The broad phase in which an operation observes a terminal condition.
- Operation
Resource Domain - Stable adapter domain that owns an operation resource terminal.
- Parse
Diagnostic Span Kind - Parsed
Editor Facts - Parser-backed editor facts produced by a diagram parse operation.
- Render
Semantic Model - Typed semantic model used by the headless renderer.
Constants§
- AGENTFLOW_
CONTAINMENT_ VIOLATION_ WARNING_ RULE_ ID - AGENTFLOW_
SHAPE_ REMOVED_ WARNING_ RULE_ ID - AGENTFLOW_
SHAPE_ UNSUPPORTED_ WARNING_ RULE_ ID - BLOCK_
WIDTH_ WARNING_ RULE_ ID - FLOWCHART_
EXPLICIT_ DIRECTION_ WARNING_ RULE_ ID - FLOWCHART_
UNKNOWN_ STYLE_ TARGET_ WARNING_ RULE_ ID - GIT_
GRAPH_ DUPLICATE_ COMMIT_ WARNING_ RULE_ ID - MAX_
DIAGRAM_ NESTING_ DEPTH - Maximum nested diagram/include depth accepted by recursive parsers.
Traits§
- Builtin
Render Semantic - Family-owned typed semantic data that can project the public compatibility JSON contract.
Functions§
- built_
in_ typed_ render_ families - Returns each compiled concrete built-in typed render-model family exactly once.
- diagram_
family_ capabilities - Returns every known Mermaid diagram id in the pinned baseline, including unavailable ones.
- diagram_
family_ selectors - Returns the complete catalog-owned mapping from logical families to Cargo selectors.
- diagram_
header_ facts - Returns known header facts for Mermaid diagram starters in the pinned baseline.
- diagram_
type_ family_ id - diagram_
type_ family_ kind - diagram_
type_ metadata_ id - diagram_
type_ render_ model_ kind - normalize_
terminal_ diagnostic - Produces a bounded, terminal-safe human-readable diagnostic.
- normalize_
terminal_ text - Normalizes untrusted authored text for terminal display without changing printable text.
- preprocess_
diagram - preprocess_
diagram_ with_ known_ type - supported_
diagrams - Returns metadata names backed by semantic parsers compiled into this build.
- supported_
themes - Returns Mermaid theme names supported by the pinned baseline.
Type Aliases§
- Custom
Json Render Parser - Parser used by a custom render-model registry overlay.
- Diagram
Semantic Parser - Parser used by a custom semantic JSON registry overlay.
- Operation
Control Result - Result channel for a controlled operation stage.
- Result