mermaid-graph-renderer

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.

85 stars

Best use case

mermaid-graph-renderer is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

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.

Teams using mermaid-graph-renderer should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/mermaid-graph-renderer/SKILL.md --create-dirs "https://raw.githubusercontent.com/curiositech/some_claude_skills/main/.claude/skills/mermaid-graph-renderer/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/mermaid-graph-renderer/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How mermaid-graph-renderer Compares

Feature / Agentmermaid-graph-rendererStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

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.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Mermaid Graph Renderer

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

```mermaid
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.

```javascript
// Lazy load pattern — only loads mermaid.js when diagrams exist
function initMermaid() {
  const diagrams = document.querySelectorAll('.mermaid');
  if (diagrams.length === 0) return;

  const script = document.createElement('script');
  script.src = 'https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js';
  script.onload = () => {
    mermaid.initialize({ startOnLoad: false, theme: 'neutral' });
    mermaid.run({ nodes: diagrams });
  };
  document.head.appendChild(script);
}

// Handle initial load + SPA navigation
document.addEventListener('DOMContentLoaded', initMermaid);
// For SPA route changes: call initMermaid() after navigation
```

**Key detail**: Handle both initial page load AND client-side navigation (SPA route changes) by re-running `mermaid.run()` when new diagram content appears.

| Aspect | Value |
|--------|-------|
| Bundle size | ~480 KB (core + lazy diagram chunks) |
| Render time | ~50-200 ms per diagram (client) |
| Diagram coverage | Full (all Mermaid types) |
| Best for | Docs sites, blogs, apps with occasional diagrams |

### Option 2: @mermaid-js/tiny

Pre-bundled subset for CDN use. All diagram types included upfront (no lazy-loading of diagram chunks). Smaller total but loaded eagerly.

**Use when**: You know exactly which 1-2 diagram types you need and want a single-file import.

### Option 3: Build-Time SSR (Usually Not Worth It)

Render SVGs at build time using Puppeteer/Playwright. Sounds appealing; painful in practice.

**Costs**:
- Adds ~280 MB to `node_modules` (Puppeteer + Chromium)
- ~2-3 seconds per diagram to spin up and render
- A 5-second build becomes 45 seconds for ~30 diagrams
- Docker/CI headaches (Chrome needs to be installed)

**When actually worth it**: Strict zero-JS requirements, or sites with hundreds of diagrams where you want to eliminate client-side rendering entirely.

**Tools**: `rehype-mermaid` (uses Playwright), `rehype-mermaid-cli` (wraps official CLI).

**Verdict**: Unless you have strict zero-JS requirements, lazy-loaded client-side rendering is the better trade-off.

---

## Offline / CLI Rendering

### Option 1: mermaid-cli (Official)

The canonical CLI tool. Launches headless Chromium, renders, captures output.

```bash
# Install
npm install -g @mermaid-js/mermaid-cli

# Basic usage
mmdc -i input.mmd -o output.svg
mmdc -i input.mmd -o output.png -b transparent
mmdc -i input.mmd -o output.pdf

# With config
mmdc -i input.mmd -o output.svg -t dark --configFile mermaid.config.json

# Batch: process Markdown with embedded diagrams
mmdc -i document.md -o document-with-images.md

# Docker
docker run --rm -v $(pwd):/data minlag/mermaid-cli -i /data/input.mmd -o /data/output.svg
```

| Aspect | Value |
|--------|-------|
| Speed | ~3000 ms per diagram (Chromium overhead) |
| Output | SVG, PNG, PDF |
| Size | ~280 MB (Puppeteer + Chromium) |
| Coverage | Full (all Mermaid types, 100% parity) |
| Best for | 1-50 diagrams, when accuracy matters most |

**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.).

```bash
# 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
```

| Aspect | Value |
|--------|-------|
| Speed | ~500-2000 ms (network + render) |
| Output | SVG, PNG, PDF, JPEG |
| Languages | 25+ (Mermaid, PlantUML, GraphViz, D2, etc.) |
| Best for | Multi-language pipelines, CI/CD, documentation generators |

**When Kroki wins**: You need multiple diagram languages in one pipeline.
**When it doesn't**: Simple "render one Mermaid diagram" — overkill.

### Option 3: mmdr (Native Rust — Fastest)

Native Rust reimplementation. No browser, no Node.js. ~1000x faster than mermaid-cli.

```bash
# Install (Rust toolchain required)
cargo install mmdr

# Usage
mmdr input.mmd -o output.svg
mmdr input.mmd -o output.png  # via resvg, no browser
```

| Aspect | Value |
|--------|-------|
| Speed | ~3 ms per diagram (1000x faster) |
| Output | SVG (native), PNG (via resvg) |
| Size | ~5-10 MB binary |
| Coverage | 13 diagram types (partial parity) |
| Best for | Batch processing 100+ diagrams, CI/CD speed |

**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.

Related Skills

typography-expert

85
from curiositech/some_claude_skills

Master typographer specializing in font pairing, typographic hierarchy, OpenType features, variable fonts, and performance-optimized web typography. Use for font selection, type scales, web font optimization, and typographic systems. Activate on "typography", "font pairing", "type scale", "variable fonts", "web fonts", "OpenType", "font loading". NOT for logo design, icon fonts, general CSS styling, or image-based typography.

pixel-art-infographic-creator

85
from curiositech/some_claude_skills

Generate pixel art diagrams and infographics in retro 16-bit SNES aesthetic — recovery education visuals, flowcharts, data visualizations, process diagrams with dithering and limited palettes. NOT for photo-realistic images, vector graphics, or high-resolution illustration.

mermaid-graph-writer

85
from curiositech/some_claude_skills

Writes precise, well-structured Mermaid diagrams for any visualization need. Use when creating flowcharts, sequence diagrams, state machines, ER models, timelines, mindmaps, Gantt charts, or any other Mermaid-supported diagram type. Activate on "mermaid", "diagram", "flowchart", "sequence diagram", "state diagram", "ER diagram", "visualize", "draw graph". NOT for rendering/exporting Mermaid to images (use mermaid-graph-renderer), ASCII art, or GUI-based design tools.

hand-drawn-infographic-creator

85
from curiositech/some_claude_skills

Generate hand-drawn style diagrams and infographics for recovery education articles. Creates anatomist's notebook aesthetic visuals - brain diagrams, timelines, social comparisons, and process flows using continuous line art, semantic color coding, and margin annotations.

competitive-cartographer

85
from curiositech/some_claude_skills

Strategic analyst that maps competitive landscapes, identifies white space opportunities, and provides positioning recommendations. Use when users need competitive analysis, market positioning strategy, differentiation tactics, or "how do I stand out?" guidance across any domain (portfolios, products, services). NOT for market size estimation or financial forecasting.

career-biographer

85
from curiositech/some_claude_skills

AI-powered career biographer that conducts empathetic interviews, extracts structured career narratives, and transforms professional stories into portfolios, CVs, and personal brand assets. This skill should be used when users want to document their career journey, create professional portfolios, generate CVs, or craft compelling career narratives.

skill-coach

85
from curiositech/some_claude_skills

Guides creation of high-quality Agent Skills with domain expertise, anti-pattern detection, and progressive disclosure best practices. Use when creating skills, reviewing existing skills, or when users mention improving skill quality, encoding expertise, or avoiding common AI tooling mistakes. Activate on keywords: create skill, review skill, skill quality, skill best practices, skill anti-patterns. NOT for general coding advice or non-skill Claude Code features.

3d-cv-labeling-2026

85
from curiositech/some_claude_skills

Expert in 3D computer vision labeling tools, workflows, and AI-assisted annotation for LiDAR, point clouds, and sensor fusion. Covers SAM4D/Point-SAM, human-in-the-loop architectures, and vertical-specific training strategies. Activate on '3D labeling', 'point cloud annotation', 'LiDAR labeling', 'SAM 3D', 'SAM4D', 'sensor fusion annotation', '3D bounding box', 'semantic segmentation point cloud'. NOT for 2D image labeling (use clip-aware-embeddings), general ML training (use ml-engineer), video annotation without 3D (use computer-vision-pipeline), or VLM prompt engineering (use prompt-engineer).

wisdom-accountability-coach

85
from curiositech/some_claude_skills

Longitudinal memory tracking, philosophy teaching, and personal accountability with compassion. Expert in pattern recognition, Stoicism/Buddhism, and growth guidance. Activate on 'accountability', 'philosophy', 'Stoicism', 'Buddhism', 'personal growth', 'commitment tracking', 'wisdom teaching'. NOT for therapy or mental health treatment (refer to professionals), crisis intervention, or replacing professional coaching credentials.

windows-95-web-designer

85
from curiositech/some_claude_skills

Modern web applications with authentic Windows 95 aesthetic. Gradient title bars, Start menu paradigm, taskbar patterns, 3D beveled chrome. Extrapolates Win95 to AI chatbots, mobile UIs, responsive layouts. Activate on 'windows 95', 'win95', 'start menu', 'taskbar', 'retro desktop', '95 aesthetic', 'clippy'. NOT for Windows 3.1 (use windows-3-1-web-designer), vaporwave/synthwave, macOS, flat design.

windows-3-1-web-designer

85
from curiositech/some_claude_skills

Modern web applications with authentic Windows 3.1 aesthetic. Solid navy title bars, Program Manager navigation, beveled borders, single window controls. Extrapolates Win31 to AI chatbots (Cue Card paradigm), mobile UIs (pocket computing). Activate on 'windows 3.1', 'win31', 'program manager', 'retro desktop', '90s aesthetic', 'beveled'. NOT for Windows 95 (use windows-95-web-designer - has gradients, Start menu), vaporwave/synthwave, macOS, flat design.

win31-pixel-art-designer

85
from curiositech/some_claude_skills

Expert in Windows 3.1 era pixel art and graphics. Creates icons, banners, splash screens, and UI assets with authentic 16/256-color palettes, dithering patterns, and Program Manager styling. Activate on 'win31 icons', 'pixel art 90s', 'retro icons', '16-color', 'dithering', 'program manager icons', 'VGA palette'. NOT for modern flat icons, vaporwave art, or high-res illustrations.