home / skills / michaelvessia / nixos-config / mermaid-to-png
This skill converts mermaid blocks in markdown to PNGs, saves images under assets, and adds references for seamless export.
npx playbooks add skill michaelvessia/nixos-config --skill mermaid-to-pngReview the files below or copy the command above to add this skill to your agents.
---
name: mermaid-to-png
description: Convert mermaid diagrams in markdown files to PNG images. Use when the user wants to export markdown with mermaid to formats that don't support mermaid (Google Docs, PDF, etc).
allowed-tools: Bash, Read
---
# Mermaid to PNG
Extracts mermaid diagrams from markdown files, renders them to PNGs, and inserts image references after each mermaid block. The original mermaid code is preserved for future editing.
## Usage
Run the script via bunx:
```bash
bunx ~/nixos-config/modules/programs/claude-code/skills/mermaid-to-png/mermaid-to-png.ts "<markdown-file>"
```
## What it does
1. Finds all ```` ```mermaid ```` code blocks in the markdown file
2. Renders each to PNG via mermaid.ink API (no local browser needed)
3. Saves PNGs to `assets/<filename-kebab-case>/diagram-N.png`
4. Inserts `` after each mermaid block
5. Preserves original mermaid code for future edits
## Output structure
```
document.md
assets/
document/
diagram-1.png
diagram-2.png
...
```
## Example
**Before:**
````markdown
# My Doc
```mermaid
graph LR
A --> B
```
````
**After:**
````markdown
# My Doc
```mermaid
graph LR
A --> B
```

````
## Notes
- Uses mermaid.ink web API (requires internet)
- Filenames are converted to kebab-case (no spaces)
- White background for compatibility
- Idempotent: re-running will regenerate PNGs but not duplicate image refs (mermaid blocks without existing image refs get new ones)
This skill converts mermaid diagrams embedded in Markdown files into PNG images and inserts image references immediately after each mermaid block. The original mermaid code is preserved so diagrams remain editable and the process is idempotent. It targets workflows that need static image exports for platforms that don't render mermaid (PDF, Google Docs, etc).
The tool scans a Markdown file for ```mermaid code blocks, sends each diagram to the mermaid.ink rendering API to produce PNGs, and writes the images into an assets/<kebab-case-filename>/ directory. After each mermaid block it inserts a corresponding  reference while keeping the original code block intact. Re-running the script regenerates images as needed but avoids creating duplicate image references.
Does this modify the original mermaid code?
No. The original mermaid code block is preserved; only a PNG reference is inserted after it.
Where are images saved?
PNGs are saved under assets/<kebab-case-source-filename>/diagram-N.png next to the Markdown file.
Do I need a browser or local mermaid install?
No. Rendering is done via the mermaid.ink web API, so a local browser or mermaid install is not required.