Renders Mermaid diagrams to SVG, PNG, and PDF in both web and offline contexts. Covers client-side lazy loading, SSR trade-offs, CLI batch export, and native Rust rendering. Use when exporting diagrams to images, optimizing Mermaid rendering performance on web pages, setting up CI/CD diagram pipelines, or choosing a rendering library. Activate on "render mermaid", "export diagram", "mermaid to png", "mermaid to svg", "mermaid performance", "diagram export". NOT for writing Mermaid syntax (use mermaid-graph-writer), general image processing, or non-Mermaid diagram formats.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
mermaid-graph-renderer
license
Apache-2.0
description
Renders Mermaid diagrams to SVG, PNG, and PDF in both web and offline contexts. Covers client-side lazy loading, SSR trade-offs, CLI batch export, and native Rust rendering. Use when exporting diagrams to images, optimizing Mermaid rendering performance on web pages, setting up CI/CD diagram pipelines, or choosing a rendering library. Activate on "render mermaid", "export diagram", "mermaid to png", "mermaid to svg", "mermaid performance", "diagram export". NOT for writing Mermaid syntax (use mermaid-graph-writer), general image processing, or non-Mermaid diagram formats.
Renders Mermaid diagrams to production-quality SVG, PNG, and PDF in web and offline contexts. Covers the full spectrum from lazy-loaded client-side rendering to 1000x-faster native Rust batch export.
Core Constraint
Mermaid.js requires browser APIs (document.createElement, SVGTextElement.getBBox()) to compute text dimensions. Every non-browser rendering path must either embed a headless browser or reimplement the renderer from scratch. This constraint shapes every decision below.
When to Use
✅ Use for:
Rendering Mermaid diagrams on web pages (performance-optimized)
Exporting diagrams to SVG, PNG, or PDF (offline/CLI)
Setting up CI/CD pipelines that generate diagram images
Choosing between rendering libraries for a project
Optimizing Mermaid load time on documentation sites
❌ NOT for:
Writing Mermaid syntax (use mermaid-graph-writer)
Rendering non-Mermaid formats (PlantUML, GraphViz — see Kroki)
General image processing or manipulation
Rendering Decision Tree
flowchart TD
A{Where are you rendering?} -->|Browser| B{Performance matters?}
A -->|CLI / CI| C{Volume?}
A -->|Server-side| D{Must avoid client JS?}
B -->|Yes| E[Lazy-load mermaid.js]
B -->|No| F[CDN script tag]
C -->|1-10 diagrams| G[mermaid-cli]
C -->|10-100 diagrams| H{Need multiple formats?}
C -->|100+ diagrams| I[mmdr Rust renderer]
H -->|Mermaid only| G
H -->|Multiple languages| J[Kroki]
D -->|Yes, zero JS| K[Build-time with Puppeteer]
D -->|Some JS OK| E
K -->|Slow builds warning| L[rehype-mermaid + Playwright]
Web Rendering
Option 1: Lazy-Loaded mermaid.js (Recommended)
Best for documentation sites, blogs, and apps where only some pages have diagrams.
How it works: Check for .mermaid elements before loading the library. The ~480 KB cost is only paid on pages that actually need it.
SVG gotcha: Output SVGs contain <foreignObject> elements that break in Inkscape and rsvg-convert. Fix: set "htmlLabels": false in config, or export to PNG instead.
Option 2: Kroki (Multi-Format Gateway)
Unified HTTP API that routes diagram source to appropriate rendering engine. Supports 25+ languages (Mermaid, PlantUML, GraphViz, D2, Excalidraw, etc.).
# Render via HTTP (self-hosted or kroki.io)
curl -X POST https://kroki.io/mermaid/svg \
-H 'Content-Type: text/plain' \
-d 'flowchart LR
A --> B --> C' \
-o diagram.svg
# Self-host via Docker Compose# docker-compose.yml needs: yuzutech/kroki + yuzutech/kroki-mermaid
Trade-off: Not all Mermaid features are supported yet. Flowcharts and sequence diagrams are mature; other types vary. Accept imperfection for speed, or fall back to mermaid-cli for edge cases.
No <foreignObject> issue: Uses native SVG text, so output works with Inkscape and other SVG tools.
Comparison Matrix
Criterion
mermaid.js CDN
mermaid-cli
Kroki
mmdr (Rust)
Runtime
Browser
Node + Puppeteer
Docker
Native binary
Speed/diagram
~100 ms
~3000 ms
~1000 ms
~3 ms
SVG quality
Excellent
Excellent
Excellent
Good (improving)
PNG quality
N/A
Good
Good
Good (resvg)
PDF export
N/A
Yes
Yes
Not yet
Install size
~480 KB
~280 MB
~1 GB (Docker)
~5-10 MB
Diagram coverage
Full
Full
Full
13 types
CI/CD fit
Poor
Moderate
Good
Excellent
Multi-language
No
No
Yes (25+)
No
Recommendations by Use Case
Use Case
Recommendation
Why
Docs site with occasional diagrams
Lazy-loaded mermaid.js
Only loads on pages that need it
Next.js / SSR app
Dynamic import, ssr: false
Don't fight build-time rendering
CI/CD generating static docs (Mermaid only)
mmdr for speed, mermaid-cli for accuracy
1000x faster vs. 100% feature parity
CI/CD with multiple diagram languages
Kroki
One API for PlantUML + Mermaid + GraphViz
Batch export for print/PDF (100+ diagrams)
mmdr + mermaid-cli fallback
Fast for most, accurate for edge cases
Desktop apps (Electron/Obsidian/VS Code)
Built-in mermaid.js
Chromium already embedded
Anti-Patterns
SSR Obsession
Wrong: Spending 3 days setting up Puppeteer in CI to avoid 480 KB of client JS.
Right: Lazy-load mermaid.js. The 480 KB is only fetched on pages with diagrams. Most users won't notice.
foreignObject Surprise
Wrong: Exporting SVGs from mermaid-cli and wondering why Inkscape can't open them.
Right: Set "htmlLabels": false in config, or export to PNG directly.
One Tool for Everything
Wrong: Using mermaid-cli for 500 diagrams in CI (25 minutes of build time).
Right: Use mmdr for batch, mermaid-cli for the few diagrams that need full parity.
Output Contract
This skill produces:
Rendered diagram output (SVG or PNG) from Mermaid syntax
Rendering configuration with theme, dimensions, and export settings
Diagram validation with syntax checking and error reporting
Batch rendering pipeline for multiple diagrams with consistent styling