Expand description
Mermaid 图表的 Rust 解析与渲染库。
支持 8 种图表:flowchart / sequence / class / state / er / pie / gitgraph / timeline。
输出统一走 lievisual 的声明式场景 IR
(Scene)与多后端(SVG / vello_cpu PNG),本 crate 不维护自有渲染后端。
§管线
Mermaid 文本 → MermaidParser → ast::Diagram
→ builder::extract (Unigraph, UG)
→ builder::measure (UG',尺寸回填)
→ builder::layout (Geograph, GG)
→ builder::materialize (SceneGraph)
→ builder::paint (lievisual::Scene)
→ 画布贴合内容 + lievisual 渲染§画布语义
与官方 mermaid 一致:width / height 是上限而非固定画布。输出 SVG 只写贴合
内容包围盒的 viewBox(根节点不写死 width / height,视口交给 CSS,用
max-width 封顶);内容超出上限时等比缩小,内容装得下时不放大
(画布贴合内容,只留少量边距)。
§示例
use liemermaid::render;
let svg = render("flowchart TD\nA[Start] --> B[End]", 800, 600).unwrap();
assert!(svg.starts_with("<svg"));
assert!(svg.contains("viewBox="), "画布几何由 viewBox 承载");Re-exports§
pub use ast::Diagram;pub use parser::WinnowParser as MermaidParser;pub use builder::types::OutputConfig;
Modules§
Structs§
- Sketch
Kinds - 手绘选项与填充样式(转发自 lievisual 的
lievisual::sketch模块)。 - Sketch
Options - 手绘选项与填充样式(转发自 lievisual 的
lievisual::sketch模块)。
Enums§
- Font
Source - Font source.
- Sketch
Fill Style - 手绘选项与填充样式(转发自 lievisual 的
lievisual::sketch模块)。 - Sketch
Kind - 手绘选项与填充样式(转发自 lievisual 的
lievisual::sketch模块)。
Functions§
- parse_
generic_ family - Parse a generic family name (
"monospace"/"sans-serif", etc.) into parley’sparley::fontique::GenericFamily. - register_
font - Register a custom font into the process-wide font collection.
- register_
font_ generic - Register a custom font and optionally associate it with a generic font family
(
GenericFamily). - render
- 渲染 Mermaid 图表为 SVG 字符串。
- render_
png - 渲染 Mermaid 图为 PNG 位图字节(供 liepress 等宿主嵌入 PDF/PNG/SVG/DOCX)。
- render_
png_ sketch - 渲染 Mermaid 图表为手绘风格 PNG 字节(形态对齐
render_png:内容放大到目标尺寸)。 - render_
png_ sketch_ with_ config - 渲染手绘 PNG,使用自定义
OutputConfig与SketchOptions。 - render_
png_ with_ config - 渲染 Mermaid 图为 PNG 字节,使用自定义
OutputConfig(可指定画布尺寸与背景色)。 - render_
sketch - 渲染 Mermaid 图表为手绘风格 SVG(rough.js 质感:抖动描边 + 排线填充)。
- render_
sketch_ with_ config - 渲染手绘 SVG,使用自定义
OutputConfig与SketchOptions。 - render_
with_ config - 渲染 Mermaid 图表为 SVG,使用自定义
OutputConfig(可指定画布尺寸与背景色)。