name: premaid description: Create, render, lint, and auto-repair Mermaid diagrams using the premaid CLI. Use when the user asks to draw/visualize something as a diagram, render a .mmd file, or clean up mermaid blocks in documentation.
premaid
Drives the premaid CLI for two workflows:
- Generate & render — user intent → Mermaid source → SVG + PNG with the
prettytheme. - Lint & fix — audit
.mmd/.mdfiles, auto-repair common mistakes.
Preflight
Check the CLI is available before anything else:
command -v premaid
If missing, ask the user to install it:
npm install -g github:O6lvl4/premaid
Workflow 1 — draw a diagram
Pick a diagram type from the user's intent:
Intent Type process / arrows / decision tree flowchartmessages between actors over time sequenceDiagramdata model / schema / relations erDiagramclass hierarchy / OO design classDiagramstate machine stateDiagram-v2project schedule / roadmap gantthistorical events on a line timelineshare of a whole piehierarchy / brainstorm mindmapstrategy placement (2×2) quadrantChartbranch/merge history gitGraphuser journey / satisfaction journeyDraft the Mermaid source. Rules that keep it renderable:
- Multi-line labels use
<br/>, not\n. - Labels with
<,>,/,(,),\,", or:+ space must be quoted:A["GET /users"]. - Inside a quoted label, escape
"as"(Mermaid does not accept\").
- Multi-line labels use
Write to
<dir>/<name>.mmd(ask the user for the path if it's not obvious from context).Render:
premaid path/to/file.mmd -o path/to/fileWrites
file.svg+file.pngwith theprettytheme (default).Verify before reporting success:
premaid lint path/to/file.mmdIf issues appear, run with
--fixand re-render.
Theme / background tweaks:
-t dark— dark slate/indigo theme-b gradient— theme-aware soft gradient-b "#F8FAFC"— any CSS color-s 3— higher-DPI PNG
Workflow 2 — audit / repair existing docs
Scan:
premaid lint <paths-or-dirs>Recurses into directories. For
.mdfiles it extracts```mermaidfences and lints only those blocks.Interpret the output. Exit code
1means issues present. Group by rule when summarizing to the user:Rule What triggers it Auto-fix literal-newline\ninside a label (renders as text)\n→<br/>unquoted-specialUnquoted label with <>/():\\"or:+ spacewrap in "...","→"unbalanced-bracketsLine-level [ ]/{ }mismatchnot auto-fixed — manual low-contraststyle X fill:#…(+ optionalcolor:#…) with WCAG ratio < 4.5inject color:#fffor#000by luminanceRepair with user consent:
premaid lint --fix <paths>Review the diff (
git diff) before committing. The auto-fixer is conservative but not semantically aware:low-contrastoverrides any existingcolor:in the matchedstyledirective. If the user deliberately styled text for a non-default background, preserve it manually.unquoted-specialauto-fix only understands the shape openers[,[[,{,{{,(,((,[(,([,[/,[\,>. Other exotic shapes may be misparsed — eyeball the diff.
Gotchas
\"does not work inside quoted labels. Use". This is the #1 cause ofparse errorin Mermaid labels.premaid lintapplies rules 1–3 only insideflowchart/graph. ClassDiagram / sequenceDiagram etc. use different syntax; the linter skips them to avoid false positives. Rule 4 (contrast) applies everywhere.- Multiple diagrams in one Markdown file are linted independently; line numbers in reports are the line in the source
.md(not within the block). - Do not trust
\nrendering even in quoted labels — Mermaid prints it literally. Always use<br/>.
Catalog reference
For inspiration and the expected visual output of each diagram type with the pretty theme, see docs/catalog/README.md in the premaid repo.