| Crates.io | figurehead |
| lib.rs | figurehead |
| version | 0.4.3 |
| created_at | 2025-12-09 10:28:35.563509+00 |
| updated_at | 2025-12-30 21:58:02.230655+00 |
| description | A Rust library to convert Mermaid.js diagram markup into ASCII diagrams |
| homepage | https://github.com/Mootikins/figurehead-rs |
| repository | https://github.com/Mootikins/figurehead-rs |
| max_upload_size | |
| id | 1975252 |
| size | 721,782 |
A Rust utility to convert Mermaid.js diagram markup into ASCII diagrams, inspired by mermaid-ascii.
Ideas: add a small banner/screenshot of a rendered flowchart once we have more diagram types; a light/dark pair of ASCII captures would fit the theme. Swap the crates.io/docs.rs badges to live ones after publishing.
Figurehead follows a modular pipeline architecture:
Input β Detector β Parser β Database β Layout β Renderer β Output
Currently supported:
Planned:
For layout/rendering review targets, see docs/ideal-output/.
# Basic conversion
echo "graph TD\n A --> B" | figurehead
# Choose output character set (ascii|unicode|unicode-math|compact)
figurehead convert --style ascii -i input.mmd
# Output to file
figurehead -i input.mmd -o output.txt
# Respect FIGUREHEAD_STYLE environment variable
FIGUREHEAD_STYLE=compact figurehead convert -i input.mmd
# Enable debug logging
figurehead convert --log-level debug --log-format pretty -i input.mmd
# Use environment variables for logging
FIGUREHEAD_LOG_LEVEL=debug FIGUREHEAD_LOG_FORMAT=json figurehead convert -i input.mmd
use figurehead::{plugins::flowchart::FlowchartDiagram, core::Diagram};
// Create a flowchart diagram
let diagram = FlowchartDiagram;
// Create parser and database
let mut parser = diagram.create_parser();
let mut database = diagram.create_database();
// Parse some markup
parser.parse("graph TD\n A --> B", &mut database)?;
// Render to ASCII
let renderer = diagram.create_renderer();
let output = renderer.render(&database)?;
println!("{}", output);
Figurehead supports single-level subgraphs to group related nodes:
echo 'graph LR
subgraph "Backend"
API --> DB
end
Client --> API' | figurehead convert -i -
Output:
βββ Backend ββββ
ββββββββββ β βββββββ ββββββ β
β Client ββββΌβΆβ API βββΆβ DB β β
ββββββββββ β βββββββ ββββββ β
ββββββββββββββββββ
Limitations:
Figurehead includes comprehensive structured logging using the tracing crate.
This helps with debugging diagram processing and understanding performance.
trace: Very detailed information for deep debuggingdebug: Detailed information for debugging (recommended for development)info: General informational messages (default)warn: Warning messageserror: Error messages onlycompact: Single-line format, good for production (default)pretty: Multi-line format with colors, good for developmentjson: JSON format, good for log aggregation systems# Enable debug logging with pretty format
figurehead convert --log-level debug --log-format pretty -i input.mmd
# Use environment variables (overrides CLI flags)
FIGUREHEAD_LOG_LEVEL=trace FIGUREHEAD_LOG_FORMAT=json figurehead convert -i input.mmd
# Filter logs by component
RUST_LOG="figurehead::plugins::flowchart::parser=debug" figurehead convert -i input.mmd
When debugging diagram processing issues, enable debug logging to see:
Example output with --log-level debug --log-format pretty:
INFO figurehead::plugins::orchestrator: Starting diagram processing pipeline
DEBUG figurehead::plugins::orchestrator: Diagram type detected diagram_type=flowchart
DEBUG figurehead::plugins::flowchart::parser: Parsing completed node_count=3 edge_count=2
DEBUG figurehead::plugins::flowchart::layout: Layout completed node_count=3 edge_count=2 width=45 height=12
DEBUG figurehead::plugins::flowchart::renderer: Rendering completed output_len=234 canvas_width=45 canvas_height=12
INFO figurehead::plugins::orchestrator: Pipeline completed successfully
cargo build
cargo test
# All tests
cargo test
# Core trait tests
cargo test --test core_traits
# Run with colors
cargo test -- --nocapture
# Run with logging enabled
RUST_LOG=debug cargo test
src/
βββ core/ # Core trait abstractions
βββ plugins/ # Diagram type implementations
β βββ flowchart/ # Flowchart plugin
βββ layout/ # Layout algorithms
βββ rendering/ # Rendering implementations
βββ cli/ # CLI interface
tests/
βββ core_traits.rs # Core functionality tests
The core library is fully WASM-compatible and includes a web example:
# Install wasm-pack if needed
cargo install wasm-pack
# Build for web
cd examples/web
./build.sh
# Build WASM module
cd examples/web
./build.sh
# Serve with Rust HTTP server
cargo run --bin server
# Then visit http://localhost:8000/
The web examples provide:
index.html): Full-featured editor with exampleseditor.html): Minimal split-pane editor with real-time updatesSee examples/web-editor/README.md for more details.
See AGENTS.md for development guidelines.
MIT License - see LICENSE file for details.