mermaid-simple-validator
v1.1.1
Published
Validate mermaid syntax in .md and .mermaid files — no browser required
Downloads
326
Maintainers
Readme
mermaid-simple-validator
Validate mermaid diagram syntax in Markdown files and .mermaid files — no browser required.
Uses JSDOM to create a fake DOM so mermaid can parse and validate diagrams purely in Node.js.
Install
npm install mermaid-simple-validatorUsage
npx mermaid-simple-validate [-L] <path><path>— a.mdfile, a.mermaidfile, or a directory (scanned recursively)-L— follow symbolic links when scanning a directory
Supported files
| Extension | Behaviour |
|------------|-----------|
| .md | Extracts ```mermaid … ``` fenced blocks; line ranges in the output exclude the fences |
| .mermaid | Validates the entire file content as a single diagram |
Examples
Validate a single file:
npx mermaid-simple-validate diagrams.mdScan a directory recursively (symlinks are skipped by default):
npx mermaid-simple-validate docs/Scan a directory and follow symlinks:
npx mermaid-simple-validate -L docs/Output
Given diagrams.md:
## Flowchart
```mermaid
flowchart TD
A --> B
B --> C
```
## Broken diagram
```mermaid
flowchart LR
X -> Y %% `->` is invalid
```npx mermaid-simple-validate diagrams.mdOutput:
diagrams.md:
block 1 (lines 4-6): valid (flowchart-v2)
block 2 (lines 12-13): INVALID
Parse error on line 2:
flowchart LR X -> Y
...
Expecting 'SEMI', 'NEWLINE', 'EOF', 'AMP', 'START_LINK', 'LINK', 'LINK_ID', got 'MINUS'
1 error(s) found.Exit code is 1 when any block fails validation, 0 otherwise.
How it works
- Scans a file or directory for
.mdand.mermaidfiles - For
.mdfiles — extracts```mermaidfenced code blocks and records their line range (excluding fences) - For
.mermaidfiles — treats the entire file content as a mermaid diagram - Creates a lightweight JSDOM window/document
- Calls
mermaid.parse()on each block - Reports success (with detected diagram type) or the parse error, including the exact line range
License
MIT
