English
Formatter
prettier-plugin-mmd formats Mermaid diagram text with Prettier. Use it for .mmd and .mermaid files and Mermaid code blocks in Markdown.
If you want your diagrams formatted but do not let Prettier format your Markdown, use the mmdfmt command instead. It formats the diagrams as the plugin does, and leaves everything else as you wrote it.
You can try formatting online in the Playground without installing anything. The Formatted tab updates as you edit the input.
Installation
Install Prettier and the plugin in your project:
sh
npm install --save-dev prettier@3 prettier-plugin-mmdThe plugin needs Node.js ^20.19.0 || ^22.13.0 || >=24.
Format your first diagram
Save this input as diagram.mmd:
mmd
flowchart LR
A --> B; B --> C; C --> D
subgraph S; E; F; endLoad the plugin with --plugin and run Prettier with --write to update the file:
sh
npx prettier --plugin prettier-plugin-mmd --write diagram.mmdThe result puts each statement on its own line and indents the subgraph:
mmd
flowchart LR
A --> B
B --> C
C --> D
subgraph S
E
F
endThe plugin also formats Mermaid code blocks in Markdown:
sh
npx prettier --plugin prettier-plugin-mmd --write README.mdSupported inputs
- Standalone files ending in
.mmdor.mermaid. - Markdown fenced code blocks marked with the language
mermaidormmd. Matching is case-sensitive:Mermaiddoes not match.
Compatibility explains syntax-error handling, known differences from mermaid.js, and the limits of the formatting guarantees.
Next steps
- Configuration: plugin registration, file selection, CLI usage, and editor setup.
- Options: indentation and line endings.