agentleFS
unreadlogsunreadlogs/node-agent-skills/skills/mermaid-diagram-builder/SKILL.md

mermaid-diagram-builder

Skill3 starsChanged 4 months agoMITView on GitHub

Use this skill whenever the user wants to create, validate, render, analyze, or repair Mermaid diagrams. It validates Mermaid syntax (reporting errors with line numbers), renders diagrams to SVG/PNG/JPG/PDF/HTML, computes graph stats (nodes, edges, actors, tasks, states, etc.), extracts mermaid code blocks from Markdown documents, and fixes common formatting issues. If the user pastes Mermaid code, wants a diagram image, or needs diagram code fixed, use this skill.

2 other projects use a version of this.

Adopted by

Most recently taken up by

  • Other versions2 projects use a version of this.

    Word for word · 1

    1. unreadlogs/AutarkChat★ 4100% same

    Edited · 0

    None found.

    Wrote their own version · 1

    1. JayRHa/AgentSkills★ 11same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository3 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    No Docker, no mermaid-cli, no system fonts or system tools required.

    line 26
  2. Very specific:

    Run from the skills/mermaid-diagram-builder/ directory (or use an absolute path to scripts/index.js).

    line 34
  3. Very specific:

    All 26 Mermaid diagram types are detected and rendered: flowchart/graph, sequenceDiagram, classDiagram, stateDiagram/stateDiagram-v2, …

    line 74

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

mermaid-diagram-builder

Native Node.js toolkit for Mermaid diagrams. All operations are driven from a single CLI (scripts/index.js) with subcommands. Every command follows a strict JSON I/O contract so results are easy for an agent to parse.

The library stack is 100% JavaScript:

  • mermaid + jsdom for parsing, validation, and SVG generation
  • @resvg/resvg-js for PNG/JPG rasterization
  • @napi-rs/canvas for JPG/PDF conversion
  • pdf-lib for PDF output
  • Bundled Liberation Sans fonts (OFL) for text rendering

No Docker, no mermaid-cli, no system fonts or system tools required.

Execution Command

node scripts/index.js <command> <arguments...>

Run from the skills/mermaid-diagram-builder/ directory (or use an absolute path to scripts/index.js).

Input / Output Schema

Inputs:

  • First argument is the subcommand name.
  • Remaining arguments are flags (--name value). Diagram code is supplied via --code "...", --input <file>, or --stdin.

stdout: a single line of JSON: { "data": <result> } stderr: on error, a single line of JSON: { "error": "message" } and the process exits with code 1.

# success
$ node scripts/index.js validate --code 'graph TD
  A --> B'
{"data":{"valid":true,"type":"flowchart","error":null,"line":null}}

# failure (invalid syntax)
$ node scripts/index.js validate --code 'graph TD
  A -- > B'
{"data":{"valid":false,"type":"flowchart","error":"...","line":2}}

Commands

CommandArgumentsOutput data
validate--code <mermaid> | --input <file> | --stdin{ valid, type, error, line, source }
rendercode input, --format svg|png|jpg|pdf|html, [--output <file>] [--theme default|dark|forest|neutral|base] [--width N] [--scale N] [--background <hex|transparent>] [--quality N]{ format, svg }, { format, base64 }, or { output, format, bytes }
statscode input, [--json]{ type, valid, lines, nonBlankLines, characters, directives, nodes, edges, ... }
jsoncode inputSame as stats --json
types—{ count, types: [{ keyword, label, description }] }
extractcode input (markdown), [--index N] [--title <string>]{ count, blocks: [{ index, startLine, code }] }
fixcode input, [--output <file>]{ fixed, bytes }

Supported diagram types

All 26 Mermaid diagram types are detected and rendered: flowchart/graph, sequenceDiagram, classDiagram, stateDiagram/stateDiagram-v2, erDiagram, journey, gantt, pie, quadrantChart, requirementDiagram, gitGraph, mindmap, timeline, sankey-beta, xychart-beta, block-beta, packet-beta, architecture-beta, kanban, C4Context, C4Container, C4Component, C4Dynamic, C4Deployment, venn-beta.

Examples

# Validate diagram code
node scripts/index.js validate --code 'sequenceDiagram
  Alice->>John: Hello'

# Render a PNG file (flows from --code or --input)
node scripts/index.js render --input diagram.mmd --format png --output out.png --width 800

# Render SVG and capture the markup
node scripts/index.js render --code 'pie title Pets
  "Dogs" : 386
  "Cats" : 85' --format svg

# Diagram stats (JSON for the agent)
node scripts/index.js stats --input diagram.mmd --json

# Extract all mermaid blocks from a Markdown doc
node scripts/index.js extract --input README.md

# Repair line endings / BOM / trailing whitespace
node scripts/index.js fix --input diagram.mmd --output fixed.mmd

Notes

  • Validation is non-destructive: invalid diagrams return valid: false plus a message and line number, with exit code 0. Real errors (missing input, unsupported format/theme, out-of-range extract index) exit with code 1.
  • Rendered SVG is sanitized (NaN/Infinity replaced) so it rasterizes cleanly in any renderer; foreignObject labels are converted to text elements so they survive rasterization.
  • Text metrics in headless environments are shimmed; output dimensions are computed from the actual diagram bounding box.
  • The test suite runs with npm test (node:test) from this directory.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.