Skip to content

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-mmd

The 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; end

Load the plugin with --plugin and run Prettier with --write to update the file:

sh
npx prettier --plugin prettier-plugin-mmd --write diagram.mmd

The 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
  end

The plugin also formats Mermaid code blocks in Markdown:

sh
npx prettier --plugin prettier-plugin-mmd --write README.md

Supported inputs ​

  • Standalone files ending in .mmd or .mermaid.
  • Markdown fenced code blocks marked with the language mermaid or mmd. Matching is case-sensitive: Mermaid does 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.

Third-party tools for Mermaid diagram text.