Render mermaid diagrams from a Markdown file (or a lone .mmd) to standalone SVGs for reuse in articles. Extracts each ```mermaid block (pure, tested) and drives a render engine (mmdc) with a strict argument vector — no shell. Engine is used only as an offline DOM->SVG renderer of our own HTML, never to control a live site (that stays the bridge's job).
| Tier | tools |
| Role | unclassified (baselined) |
| Path | crates/tools/mermaid-render |
| Edition | 2021 |
| Targets | tools-mermaid-render, tools_mermaid_render, render_live |
| Public items | 12 across 0 modules |
| Tests | 13 |
What it is for
tools-mermaid-render — extract mermaid diagrams from Markdown and name their output SVGs. This library is the PURE half: block extraction, slugging, output naming. The subprocess render lives in main.rs.
Deliberate scope limits (operator, 2026-08-08):
- SVG only. There is no format parameter anywhere. The tool cannot emit
PNG/PDF, so it cannot be talked into a different output.
- Not an agent-arbitrary capability. The CLI surface is two paths in
(input file, output dir) and SVG files out. It takes no URL, no shell, no pass-through flags, so it cannot be repurposed to control a browser. The render engine (mmdc/puppeteer) is used ONLY as an offline DOM→SVG renderer of our own generated HTML; live-site control stays the bridge's job. Invoke it from the /diagram skill or by hand, never as a free tool a model reaches for.
Capabilities
crate root
tools-mermaid-render — extract mermaid diagrams from Markdown and name their
| Item |
|---|
pub const MAX_INPUT_BYTES: u64 |
pub const MAX_SVG_BYTES: usize |
pub const RENDER_TIMEOUT: std::time::Duration |
pub const RENDERER_VERSION: & str |
fn puppeteer_config(dir : & std::path::Path) -> anyhow::Result <Option <std::path::PathBuf>> |
fn render_to_svg(source : & str, work_dir : & std::path::Path) -> anyhow::Result <String> |
fn slugify(s : & str) -> String |
fn output_name(stem : & str, index : usize, heading : Option <& str>) -> String |
Block
tools-mermaid-render — extract mermaid diagrams from Markdown and name their
| Item |
|---|
pub const MAX_BLOCK_BYTES: usize |
pub const MAX_BLOCKS: usize |
pub struct Block |
fn extract_blocks(md : & str) -> Vec <Block> |
How to use it
No examples/ target and no doctest in this crate's rustdoc. The tests listed under Verification are the closest executable usage.
Module structure
No public modules: the crate root is its whole surface.
Public surface
`crate root`
| Item | What it is |
|---|---|
pub const MAX_INPUT_BYTES: u64 | Cap on the Markdown input we will read (bytes) |
pub const MAX_BLOCK_BYTES: usize | Cap on one block's mermaid source (bytes) |
pub const MAX_SVG_BYTES: usize | Cap on an SVG accepted back from the renderer (bytes) |
pub const RENDER_TIMEOUT: std::time::Duration | Wall-clock cap for one block |
pub const RENDERER_VERSION: & str | The renderer's identity, stored beside each SVG so a mermaid upgrade that changes output is visible as a version difference rather than a silent redraw. |
fn puppeteer_config(dir : & std::path::Path) -> anyhow::Result <Option <std::path::PathBuf>> | Resolve a Puppeteer config so mmdc reuses the system Chrome instead of downloading its own |
fn render_to_svg(source : & str, work_dir : & std::path::Path) -> anyhow::Result <String> | Render one mermaid source to SVG text, using work_dir for the transient source and output files |
pub const MAX_BLOCKS: usize | Cap on diagrams per file |
pub struct Block | One extracted diagram: the nearest preceding heading (for naming) and the mermaid source between the fences. |
fn extract_blocks(md : & str) -> Vec <Block> | Extract every `mermaid fenced block from Markdown, in document order |
fn slugify(s : & str) -> String | Lowercase kebab slug: alphanumerics kept, every run of other chars becomes a single -, trimmed |
fn output_name(stem : & str, index : usize, heading : Option <& str>) -> String | Output filename for block index (0-based) of a file whose stem is stem |
No pub use re-exports: every item above is declared in this crate.
Boundary
Depends on no other workspace tier.
Shares tier tools with 84 other crates: tools-advisory-reach, tools-archive-guard, tools-artifact-scaffold, tools-ask-ai-core, tools-ask-ais, tools-ask-gemini, tools-book, tools-book-report, … (84 total).
_What this crate deliberately does NOT own is a judgment. No committed registry records one for it, so none is stated here._
Where it sits
| Tier (ontology) | tools |
| Architectural role (taxonomy) | unclassified (baselined) |
| Location | crates/tools/mermaid-render |
| Vocabulary in force (lexicon) | current |
Dependencies
Runtime, from outside the workspace.
| Crate | Requirement | Features | Optional | Only on |
|---|---|---|---|---|
anyhow | ^1 | — | no | always |
Development. None.
Build. None.
Depended on by. 1 workspace crate.
Signal flow — what reaches this crate, and what it reaches.
flowchart LR n_tools_corpus["tools-corpus"] -->|uses| SELF SELF["tools-mermaid-render"] classDef self fill:#1f883d,stroke:#1f883d,color:#fff; class SELF self;
Feature flags
No Cargo features are defined: every capability is unconditional, so no consumer can receive a half-wired crate.
Targets
| Kind | Name | Source |
|---|---|---|
| bin | tools-mermaid-render | `src/main.rs` |
| lib | tools_mermaid_render | `src/lib.rs` |
| test | render_live | `tests/render_live.rs` |
Error model
No public error type was detected: no public item declares a type named *Error, and no public signature returns one.
Operational characteristics
| Property | Evidence |
|---|---|
| async public surface | none detected |
| async runtime | none detected |
| database access | none detected |
| network I/O | none detected |
| unsafe code | none detected |
| environment variables | yes |
No unsafe block, unsafe fn, unsafe impl or unsafe trait was found by the parser anywhere in this crate's source.
Configuration
| Variable | Read in |
|---|---|
MERMAID_MMDC | src/lib.rs |
MERMAID_PUPPETEER_CONFIG | src/lib.rs |
Related capabilities
1 workspace crate depends on this one: tools-corpus.
Verification
| Kind | Count |
|---|---|
| Unit tests | 9 |
| Integration tests | 4 |
| Examples | 0 |
| Doctests | 0 |
Evidence by module. How often each public module is named by something executable.
| Module | Tests | Examples | Consumers |
|---|---|---|---|
crate root | 12 | 0 | 5 |
What the tests establish, by name:
a_flowchart_renders_to_svg—tests/render_live.rsa_source_over_the_cap_is_refused_without_spawning_anything—tests/render_live.rsan_empty_source_is_refused_without_spawning_anything—tests/render_live.rssource_that_is_not_a_diagram_is_refused_rather_than_stored—tests/render_live.rsextracts_blocks_in_order_with_nearest_heading—src/lib.rsheading_section_numbers_are_stripped—src/lib.rsnon_mermaid_fences_are_ignored—src/lib.rsoutput_names_are_indexed_and_slugged—src/lib.rsslugify_is_kebab_and_never_empty—src/lib.rsboth_flags_parse_in_either_order—src/main.rshelp_flags_detected_and_nothing_else—src/main.rsmissing_either_flag_is_an_error—src/main.rsunknown_flag_is_rejected—src/main.rs
Documentation coverage
| Measure | Documented | Total |
|---|---|---|
| Public items with rustdoc | 12 | 12 |
Public modules with a //! block | 0 | 0 |
pie showData
title Public items with rustdoc
"Documented" : 12
"No rustdoc detected" : 0
Metrics
| Metric | Value |
|---|---|
| Rust source files | 2 |
| Source lines | 622 |
| Code lines | 468 |
| Public API items | 12 |
| Public modules | 0 |
| Tests | 13 |
| Examples | 0 |
| Cargo features | 0 |
| Direct runtime dependencies | 1 |
| Workspace reverse dependencies | 1 |
pie showData
title Public API by kind
"constant" : 6
"function" : 5
"struct" : 1
pie showData
title Rust source composition
"Code" : 468
"Blank or comment" : 154
Generation
Rendered by tools-corpus corpus readme from repository evidence alone, renderer schema 2, lexicon current. No model, network service or database was consulted. Regenerate with tools-corpus corpus readme --write; verify with --check.