Extract Ferrite's native MermaidJS diagram renderer into a standalone, pure-Rust crate that can generate diagrams as SVG, PNG, or render directly to GUI frameworks like egui.
The Rust ecosystem lacks a comprehensive, pure-Rust solution for rendering Mermaid diagrams. Current options require Node.js (mermaid-cli), only support single diagram types (Pisnge for pie charts), or only generate syntax without rendering. This forces Rust projects to either:
- Depend on Node.js installation
- Use client-side JavaScript
- Go without diagram support
- Static site generator developers (mdBook, Zola, Cobalt)
- Documentation tool authors
- CLI tool developers who need diagram generation
- GUI application developers (egui, iced, druid)
- WASM application developers
- Create the first comprehensive pure-Rust Mermaid graphical renderer
- Support all major Mermaid diagram types (11 types)
- Provide multiple output backends (SVG, PNG, egui)
- Zero Node.js or JavaScript dependencies
- Easy integration for Rust projects
- 100% MermaidJS syntax compatibility (aim for 90%+ of common usage)
- Interactive diagrams (static rendering only)
- Custom diagram types beyond Mermaid spec
- Real-time collaborative editing
-
Diagram Parsing
- Flowchart (TD, TB, LR, RL, BT directions)
- Sequence Diagram
- Class Diagram
- State Diagram
- Entity-Relationship Diagram
- Pie Chart
- Gantt Chart
- Git Graph
- Mindmap
- Timeline
- User Journey
-
SVG Output
- Generate valid SVG strings
- Proper viewBox and sizing
- Embedded fonts or system font fallback
- Works in all major browsers
-
Error Handling
- Graceful handling of invalid syntax
- Informative error messages with line/column
- No panics on any input
-
Basic Theming
- Light and dark color schemes
- Configurable colors
-
egui Backend
- Render directly to egui Painter
- Widget wrapper for easy integration
- Theme integration with egui Visuals
-
PNG Output
- Convert SVG to PNG via resvg
- Configurable resolution/DPI
- Transparent background option
-
Comprehensive Documentation
- Supported syntax reference
- Examples for each diagram type
- Integration guides
-
Additional Backends
- iced integration
- wgpu direct rendering
- PDF output
-
Advanced Features
- Custom themes (import/export)
- Subgraph support improvements
- Click regions for interactivity metadata
The crate must use a backend-agnostic architecture:
mermaid source → Parser → AST → Layout → RenderBackend → Output
Where RenderBackend is a trait with implementations for:
- SVG (string output)
- egui (Painter integration)
- PNG (via SVG + resvg)
Core (always included):
- None beyond std
Optional (feature-gated):
- egui (for egui backend)
- resvg (for PNG output)
- serde (for AST serialization)
- Parse + render flowchart with 50 nodes: < 10ms
- Memory usage: < 10MB for large diagrams
- SVG output size: reasonable (not excessively verbose)
- Rust 1.70+ (match Ferrite's MSRV)
- All tier-1 platforms (Windows, Linux, macOS)
- WASM compatible (for SVG backend)
Complete and test all diagram types within Ferrite. Add error handling and basic theming.
Create RenderBackend trait and refactor current code to use it. Verify Ferrite still works.
Implement SVG output. Create CLI example. Test in browsers.
Create separate repository. Move code. Set up CI. Write documentation.
Add PNG output. Polish. Publish to crates.io.
Replace Ferrite's internal mermaid.rs with the external crate.
- All 11 diagram types render correctly
- SVG output validates and displays in Chrome, Firefox, Safari
- egui backend matches current Ferrite quality
- 100+ crates.io downloads in first month
- Positive community reception (Reddit, HN)
- Scope creep - Limit to MermaidJS parity, don't invent new features
- Text measurement - Different across backends; provide sensible defaults
- Competition - Move quickly to establish presence
- Maintenance burden - Clear scope, good documentation
- Crate name:
mermaid-render,chartlet, or other? - Should we support Mermaid config directives?
- How to handle fonts across different backends?
- License: MIT to match Ferrite, or dual MIT/Apache-2.0?
- Lines of code: ~4000
- Diagram types: 11
- Node shapes: 10+ for flowchart
- Edge styles: 3 (solid, dotted, thick)
- Arrow types: 4 (arrow, circle, cross, none)