Export DOT/Graphviz diagrams from documents to SVG images.
Automatically render DOT/Graphviz diagrams in documents to PNG images (default) using the dot-renderer tool. Use --format=svg for scalable vector output.
~/.claude/tools/dot-renderer/
├── render-dot.js # Single diagram renderer
└── process-document.js # Full document processor
When creating a document with DOT diagrams, use the standard DOT syntax in code blocks:
# My Document
Here's the graph:
```dot
digraph G {
rankdir=LR
A [label="Start"]
B [label="Process"]
C [label="End"]
A -> B -> C
}
More content...
### Step 2: Export Diagrams to PNG
After creating/editing a document with DOT blocks, run:
```bash
node ~/.claude/tools/dot-renderer/process-document.js <document-path> --verbose
Options:
--format=<fmt> - Output format: png (default) or svg--layout=<engine> - Force layout engine for all diagrams: dot, neato, circo, fdp, twopi, osage, patchwork--verbose - Show detailed progress--dry-run - Preview without making changesNOTE: PNG is the default format for maximum compatibility with markdown previewers. Use --format=svg when scalable vector output is needed.
The tool will:
\``dot, ```graphviz, or ```gv`)diagrams/{document-name}/Output structure:
document.md
diagrams/
└── document/
├── diagram-1.png
├── network-topology.png
└── class-hierarchy.png
Document transformation:
<!-- Before -->
```dot
digraph { A -> B }
---
## Layout Engines
Choose the appropriate layout engine for your graph type:
| Engine | Best For | Description |
|--------|----------|-------------|
| `dot` | Hierarchical graphs | Directed graphs, org charts, flowcharts (default) |
| `neato` | Undirected graphs | Network diagrams, social networks |
| `fdp` | Large graphs | Force-directed placement, clusters |
| `circo` | Circular layouts | Ring structures, cyclic dependencies |
| `twopi` | Radial layouts | Tree-like structures radiating from center |
| `osage` | Clustered layouts | Nested clusters, module diagrams |
| `patchwork` | Treemaps | Space-filling rectangular layout |
### Specifying Layout
Three ways to specify layout engine:
**1. In the code fence:**
```markdown
```dot:neato
graph G { A -- B -- C -- A }
**2. In the DOT code (comment):**
```dot
// layout: fdp
graph G { A -- B -- C }
3. In the DOT code (attribute):
digraph G {
layout=circo
A -> B -> C -> A
}
4. CLI override (applies to all diagrams):
node ~/.claude/tools/dot-renderer/process-document.js doc.md --layout=neato
To render a single diagram without processing a full document:
# From a .dot file
node ~/.claude/tools/dot-renderer/render-dot.js diagram.dot output.svg
# From stdin
echo "digraph { A -> B }" | node ~/.claude/tools/dot-renderer/render-dot.js --stdin output.svg
# With specific layout
node ~/.claude/tools/dot-renderer/render-dot.js diagram.dot output.svg --layout=neato
# Other output formats
node ~/.claude/tools/dot-renderer/render-dot.js diagram.dot output.json --format=json
| Extension | Image Syntax Used |
|---|---|
.md, .markdown |
 with HTML comment |
.html, .htm |
<img> tag with HTML comment |
.mdx |
JSX <img> with JSX comment |
.rst |
.. image:: directive |
.adoc |
image:: macro |
All these are equivalent:
\``dot` - Standard DOT\``graphviz` - Full name alias\``gv` - Short aliasWith layout hint:
\``dot:neato`\``graphviz:circo`\``gv:fdp`This skill works together with the diagramming skill:
Recommended workflow:
Diagrams are named based on:
digraph MyGraph { → mygraph.svglabel="Network Topology" → network-topology.svgdiagram-1, diagram-2, etc.To control naming, use a named graph:
digraph NetworkTopology {
A -> B -> C
}
→ Generates networktopology.svg
To edit a previously rendered diagram:
The renderer supports multiple output formats:
| Format | Extension | Use Case |
|---|---|---|
svg |
.svg |
Web, documents, scalable (default) |
dot |
.dot |
Canonical DOT output |
json |
.json |
Graph structure as JSON |
dot_json |
.json |
DOT with JSON output |
xdot_json |
.json |
Extended DOT with JSON |
Install dependencies: cd ~/.claude/tools/dot-renderer && npm install
graph for undirected with neato, digraph for directed)neato or fdpdotcirco or twopiThe tool auto-sizes based on diagram content. For custom sizing, edit the generated SVG or use CSS in your document.
# Process a markdown file
node ~/.claude/tools/dot-renderer/process-document.js ./docs/README.md --verbose
# Process with specific layout for all diagrams
node ~/.claude/tools/dot-renderer/process-document.js ./docs/network.md --layout=neato
# Dry run to see what would happen
node ~/.claude/tools/dot-renderer/process-document.js ./docs/README.md --dry-run
# Render single diagram with circo layout
node ~/.claude/tools/dot-renderer/render-dot.js ./diagrams/cycle.dot ./output/cycle.svg --layout=circo
digraph G {
A -> B -> C
B -> D
}
graph G {
A -- B -- C
B -- D
}
digraph G {
node [style=filled]
// Infrastructure (blue)
Cloud [fillcolor="#E3F2FD" color="#1565C0" fontcolor="#0D47A1"]
// Service (green)
API [fillcolor="#E8F5E9" color="#2E7D32" fontcolor="#1B5E20"]
// Data (amber)
DB [fillcolor="#FFF8E1" color="#F57F17" fontcolor="#E65100"]
Cloud -> API -> DB
}
digraph G {
subgraph cluster_frontend {
label="Frontend"
style=filled
fillcolor="#E3F2FD"
UI; Components
}
subgraph cluster_backend {
label="Backend"
style=filled
fillcolor="#E8F5E9"
API; Services
}
UI -> API
}