Run Mermaid diagrams from Markdown inside Emacs using the mmdc CLI.
Place your cursor inside a mermaid block, trigger a command, and
get an instant preview — no wrappers, no servers, no reimplementation.
This package shells out to the official Mermaid CLI (mmdc) to render
diagrams, then displays the result in a separate Emacs buffer.
It also automatically adapts diagram colors to your current Emacs theme.
Most Mermaid integrations either embed a renderer or add unnecessary layers. This package stays minimal: use the existing CLI, integrate it tightly into your editing workflow, and keep the feedback loop fast.
This package requires the Mermaid Command Line Interface. You must have Node.js installed.
npm install -g @mermaid-js/mermaid-cliVerify the installation by running:
mmdc --version(package-install 'markdown-mermaid)Using elpaca (recommended)
(use-package markdown-mermaid
:ensure (markdown-mermaid :type git :host github :repo "pasunboneleve/markdown-mermaid")
:bind (:map markdown-mode-map
("C-c m" . markdown-mermaid-preview)))(use-package markdown-mermaid
:vc (:url "https://github.com/pasunboneleve/markdown-mermaid" :rev :newest)
:bind (:map markdown-mode-map
("C-c m" . markdown-mermaid-preview)))- Clone this repository:
git clone https://github.com/pasunboneleve/markdown-mermaid.git ~/.emacs.d/site-lisp/markdown-mermaid- Add to your
init.el:
(add-to-list 'load-path "~/.emacs.d/site-lisp/markdown-mermaid")
(require 'markdown-mermaid)Think of this as: run mmdc at point.
-
Open a Markdown file (
.md). -
Create a Mermaid code block:
graph TD;
A[Start] --> B{Is it working?};
B -- Yes --> C[Great!];
B -- No --> D[Check Logs];
-
Place your cursor anywhere inside the code block.
-
Run:
M-x markdown-mermaid-preview- or your keybinding (e.g.
C-c m)
A new buffer opens with the rendered diagram.
Customize via:
M-x customize-group RET markdown-mermaid
| Variable | Default | Description |
|---|---|---|
markdown-mermaid-mmdc-path |
(executable-find "mmdc") |
Path to the Mermaid CLI executable. Set manually if Emacs cannot find it. |
markdown-mermaid-temp-files |
nil |
Internal: tracks temporary files for cleanup. |
The diagram automatically adapts to your current Emacs theme:
- Background →
defaultbackground - Text →
defaultforeground - Borders →
font-lock-type-face - Lines / arrows →
font-lock-constant-face
- Ensure you installed it:
npm install -g @mermaid-js/mermaid-cli- If using
nvm, Emacs may not inherit your PATH. Set it manually:
(setq markdown-mermaid-mmdc-path "/home/user/.nvm/versions/node/v14/bin/mmdc")Check the *mermaid-error* buffer for CLI output and syntax errors.
Run tests locally:
make test