Core extraction, validation, and discovery utilities for mermaid-lint — the engine that finds Mermaid diagrams in Markdown (and .mmd) files, validates them, and reports diagnostics.
ESM-only. Requires Node >= 22.
Install
npminstall@mermaid-lint/core
Public API
Extraction
Symbol
Signature
Description
extractMermaidBlocks
(path, text, options?) => Block[]
Extract every Mermaid block from a Markdown document, or the whole file as one diagram when path ends in .mmd.
Validate a Block end to end: structural checks, semantic warnings (at the given per-rule severities), fast Rust parser with a mermaid.js fallback. index is an optional pre-built SuppressionIndex (built from block when omitted) so callers that already have one (e.g. blockToDiagnostics) don't rebuild it.
Run the semantic rule set (self-loops, duplicate ids, orphan nodes, sequence/class checks, …) at the given per-rule severities; skips rules resolved to off. Same optional pre-built index as validateBlock.
SemanticWarning
interface
{ rule, message, line?, severity }.
Suppression directives
Symbol
Signature
Description
parseBodyDirectives
(lines) => Directive[]
Parse every %% suppression directive in a diagram body (next-line, range, diagram scope).
parseFileDirectives
(text) => Directive[]
Parse every <!-- mermaid-lint-disable-file ... --> directive in a Markdown document, with real document line numbers. Ignores directive syntax shown inside a fenced code block or an inline code span (documentation examples), so it never mistakes prose for a live directive.
buildSuppressionIndex
(bodyLines, fileDirectives?) => SuppressionIndex
Build the queryable suppression state for one diagram body plus any document-level directives attached to it.
A problem found while parsing a directive (missing reason, empty/unknown rules, an unmatched enable, mermaid named at line scope, or a keyword used at the wrong scope).
SYNTAX_RULE_ID
'mermaid'
The rule id reserved for syntax errors from the parser; the only id a directive can name to suppress a syntax error.
RULE_IDS_EXCLUDED_FROM_ALL
ReadonlySet<string>
Rule ids the all wildcard never covers: SYNTAX_RULE_ID and the three suppression-* meta-rules. Name them explicitly to suppress them.
Rules
Symbol
Signature
Description
resolveRules
(opts?) => ResolvedRules
Resolve { rules?, semantic? } into a concrete severity for every rule, layered over RULE_DEFAULTS (semantic: false disables all).
RULE_DEFAULTS
ResolvedRules
The default severity for every rule.
ALL_RULE_IDS
RuleId[]
Every known rule id.
isRuleSeverity
(value) => value is RuleSeverity
Type guard for 'off' | 'warn' | 'error'.
RuleId
type
Union of rule ids ('duplicate-ids' | 'no-self-loop' | …).
RuleSeverity
type
'off' | 'warn' | 'error'.
RulesConfig
type
Partial<Record<RuleId, RuleSeverity>> — user overrides.
ResolvedRules
type
Record<RuleId, RuleSeverity> — a severity for every rule.
EmittedSeverity
type
'warn' | 'error' — the severities a finding can carry.