Skip to content

@tank/mermaid-charts

1.0.0
Skill

Description

Author and validate Mermaid diagrams (flowchart, sequence, class, state, ER, gantt, pie, mindmap, gitGraph, C4, journey, quadrant, timeline, sankey, xychart, block, packet, kanban, architecture, radar). Bundled validator runs the official mermaid.parse() grammar locally via Node + jsdom — same parser GitHub uses. Covers chart-type selection, per-diagram syntax, error → fix lookup, and CI integration..

Review Recommended
tank install -g @tank/mermaid-charts

Scan completed — 2 findings

0 critical, 0 high, 2 medium — see security tab for details.

Mermaid Charts

Write Mermaid diagrams that render on the first try — and prove it by running the same parser the renderer uses.

Core Philosophy

  1. The parser is the source of truth. Mermaid syntax has many edge cases (reserved words, quoting, arrow variants). Do not guess whether a chart is valid — run scripts/validate-mermaid.mjs and let the official mermaid.parse() grammar answer.
  2. Pick the right diagram for the relationship. A flowchart for a state machine is a smell. See references/chart-selection.md before authoring.
  3. Validate every chart before claiming the task is done. "Looks right" is not done. The validator returning exit code 0 is done.
  4. Read the error, do not shotgun fixes. Mermaid parse errors point at a line and a token. Fix the indicated token, re-run, repeat. See references/common-syntax-errors.md for the error → fix lookup table.
  5. Prefer minimal, scannable diagrams. A 40-node flowchart is unreadable. If a diagram needs explanation, split it or restructure it.

When to Validate

SituationAction
You wrote a new mermaid blockRun validator before reporting
User reports a chart "doesn't render"Run validator first, then triage
Editing a doc that contains mermaid blocksRe-validate after edits
Generating mermaid in code (templates, RAG output)Validate in CI / pre-commit
Reviewing a PR that touches .md / .mdx with mermaidRun validator on changed files

Quick-Start: Validate a Chart

One-time setup (per project)

cd scripts/
npm install      # installs mermaid + jsdom (pinned in package.json)

Validate

# Validate all .md / .mdx files in a directory tree:
node scripts/validate-mermaid.mjs path/to/docs/

# Validate a single file:
node scripts/validate-mermaid.mjs path/to/diagram.md

# Validate a raw .mmd file or piped chart text:
node scripts/validate-mermaid.mjs --stdin < diagram.mmd
echo 'flowchart TD\n A --> B' | node scripts/validate-mermaid.mjs --stdin

Exit code 0 = all diagrams valid. Exit code 1 = at least one parse error (printed in file:line: message format for editor jump-to-line). Exit code 2 = validator itself crashed.

→ See references/validation-workflow.md for CI integration, error interpretation, and the "passes here = renders there" guarantee.

Quick-Start: Common Problems

"Parse error on line N — Lexical error, Unrecognized text"

The token before the caret is the problem. Most common causes:

  1. Reserved keyword used as a node ID (end, class, default, subgraph, direction, style, linkStyle). Rename or quote: Node1["end"].
  2. Unbalanced brackets: A[Label missing ], A((Circle) missing ).
  3. Wrong arrow for diagram type — flowchart uses -->, sequence uses ->>, class uses <|--, ER uses ||--o{. See references/mermaid-syntax-cheatsheet.md.
  4. Special characters in unquoted labels — (), :, ;, #. Wrap label in quotes: A["label: with colon"].

→ Full catalog in references/common-syntax-errors.md.

"No diagram type detected"

The first non-empty, non-comment line must be a diagram declaration: flowchart TD, sequenceDiagram, classDiagram, stateDiagram-v2, erDiagram, gantt, pie, mindmap, gitGraph, journey, quadrantChart, timeline, sankey-beta, xychart-beta, block-beta, packet-beta, kanban, architecture-beta, radar-beta, C4Context.

Frontmatter (---\n...\n---) is the only allowed prefix.

"Chart renders on Mermaid Live but not on GitHub"

Version skew. The bundled validator pins Mermaid to the same major version as common renderers. Re-run the validator; if it passes here, it renders on GitHub. If it fails, fix the indicated issue.

Decision Trees

Which Diagram Type?

You are showing…UseDeclaration
Process / decision flowFlowchartflowchart TD
Interaction over time between actorsSequence diagramsequenceDiagram
OO structure (classes, inheritance)Class diagramclassDiagram
State machine / lifecycleState diagramstateDiagram-v2
Data model / table relationshipsER diagramerDiagram
Project scheduleGanttgantt
Proportional parts of a wholePiepie
Concept hierarchy / brainstormMindmapmindmap
Git branching / release historyGit graphgitGraph
User journey with emotionUser journeyjourney
2x2 strategic matrixQuadrantquadrantChart
Events on a horizontal axisTimelinetimeline
Flow volumes between stagesSankeysankey-beta
Trend over numeric axesXY chartxychart-beta
System architecture (services, edges)Architecturearchitecture-beta
Software architecture (Context/Container/Component)C4C4Context

If your chart needs 2+ of these at once, you picked the wrong type — split the chart. See references/chart-selection.md for anti-patterns.

Validate-or-not?

SignalValidate?
Hand-wrote a chartYes
Edited an existing chartYes
Copy-pasted from Mermaid Live EditorYes (version skew)
Generated programmaticallyYes (always)
Chart was already in the repo and untouchedNo

Authoring Workflow

  1. Pick the diagram type using the table above.
  2. Write the chart following the per-type syntax in references/mermaid-syntax-cheatsheet.md.
  3. Validate with node scripts/validate-mermaid.mjs <path>.
  4. If errors: open references/common-syntax-errors.md, find the error pattern, apply the fix, re-validate.
  5. If clean: the chart will render anywhere the official Mermaid parser runs (GitHub, GitLab, Notion, Obsidian, VS Code preview, mermaid.live).
  6. Only then mark the authoring task complete.

Reference Files

FileContents
references/mermaid-syntax-cheatsheet.mdPer-diagram syntax: declarations, nodes, edges/arrows, labels, subgraphs, styling. One section per diagram type.
references/common-syntax-errors.mdError message → fix lookup. Reserved keywords, quoting rules, arrow mismatches, indentation, frontmatter pitfalls.
references/chart-selection.mdWhen to use each diagram type. Anti-patterns (flowchart-as-state-machine, sequence-as-flowchart). Splitting heuristics.
references/validation-workflow.mdRunning the validator, interpreting output, CI integration, the parser-equivalence guarantee, troubleshooting.

Scripts

ScriptPurpose
scripts/validate-mermaid.mjsValidates all mermaid blocks in .md/.mdx files or a piped chart. Uses the official mermaid.parse() grammar via Node+jsdom.
scripts/package.jsonPins mermaid and jsdom so behavior is reproducible. Run npm install in scripts/ once.

Command Palette

Search packages, docs, and navigate Tank