MermaidGuard operates on three main pillars: Scanning, Validation, and Autofix.
The tool accepts glob patterns (defaults to **/*.md) to find Markdown files. It parses the Markdown AST using unified/remark to locate code blocks tagged with mermaid.
Each found Mermaid diagram is passed to the Engine, which executes a set of rules.
- Rule ID:
syntax/valid-mermaid - Description: Compiles the diagram using the internal Mermaid library to ensure it is syntactically valid.
- Behavior: If compilation fails, an error diagnostic is reported with the line/column of the syntax error.
MermaidGuard enforces WCAG standards by checking for accessibility tags in diagrams.
- Rule:
accessibility/title-required- Checks if the diagram has a title (e.g.,accTitle: ...). - Rule:
accessibility/desc-required- Checks if the diagram has a description (e.g.,accDescr: ...).
When run with --fix, the Fixer module processes diagnostics that contain a fix payload.
- How it works:
- The Linter identifies missing A11y tags.
- The Rule generates a Diagnostic with a
fixobject containing the text to insert (e.g., defaultaccTitle). - The Fixer applies these edits to the source string.
- The CLI writes the modified content back to the disk.
Note: Syntax errors are generally NOT auto-fixable as they vary wildly in cause.
Diagnostics are output to the console with:
- Severity: Error (Red), Warning (Yellow), Info (Blue).
- Location: Line and Column number.
- Rule ID: The ID of the rule that triggered the diagnostic.