| Crates.io | mdbook-mermaid-ssr |
| lib.rs | mdbook-mermaid-ssr |
| version | 0.3.0 |
| created_at | 2025-12-30 21:14:40.84496+00 |
| updated_at | 2026-01-02 01:14:08.13818+00 |
| description | mdbook preprocessor to add mermaid support with server-side rendering |
| homepage | https://github.com/CommanderStorm/mdbook-mermaid-ssr |
| repository | https://github.com/CommanderStorm/mdbook-mermaid-ssr |
| max_upload_size | |
| id | 2013318 |
| size | 6,850,811 |
A preprocessor for mdbook to add mermaid.js support.
[!IMPORTANT]
mdbook-mermaid-ssrprovides server-side rendering for Mermaid diagrams in mdBook. Unlike the originalmdbook-mermaidwhich uses client-side JavaScript rendering,mdbook-mermaid-ssrpre-renders all diagrams to SVG during the build process using headless Chrome.This is not an upgrade/competition - it's a separate package with different requirements and behavior.
For the original client-side rendering version, see mdbook-mermaid.
To migrate between the two, please apply this diff:
+ [preprocessor.mermaid-ssr] - [preprocessor.mermaid] - command = "mdbook-mermaid" - - [output.html] - additional-js = ["mermaid.min.js", "mermaid-init.js"]
It turns this:
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
into this:

in your book.
To install it from source:
cargo install mdbook-mermaid-ssr
This will build mdbook-mermaid-ssr from source.
cargo-binstallIf you have cargo-binstall already:
cargo binstall mdbook-mermaid-ssr
This will download and install the pre-built binary for your system.
Binary releases are available on the Releases page.
Download the relevant package for your system, unpack it, and move the mdbook-mermaid-ssr executable into $HOME/.cargo/bin:
Chrome or Chromium must be installed on the system where you build your book. The preprocessor uses this to render Mermaid diagrams to SVG.
mdbook-mermaid-ssrAdd the following to your book.toml:
[preprocessor.mermaid-ssr]
That's it! No JavaScript files or additional configuration needed. Diagrams are pre-rendered to SVG during the build process.
mdbook-mermaid-ssr supports various configuration options in your book.toml:
[preprocessor.mermaid-ssr]
# Timeout for rendering operations (default: 30s)
timeout = "30s"
# Error handling: "fail" (default) or "comment"
# - "fail": Build fails on rendering errors
# - "comment": Errors are emitted as Markdown Annotations
on-error = "comment"
# Custom path to Chrome/Chromium executable (optional)
chrome-path = "/usr/bin/chromium"
# We also support all of mermaid.js options (but kebab-case instead of camelCase), such as:
# - `theme` with options: "default" (default), "base", "dark", "forest", "neutral"
# - `look` with options: "classic" (default), "handDrawn"
# - `security-level` with options: "strict" (default), "loose", "antiscript", "sandbox"
# - `font-family`
# - ... please see https://mermaid.js.org/config/schema-docs/config for a full list
Finally, build your book:
mdbook path/to/book
mdbook-mermaid-ssr launches a headless Chrome browserThe mermaid.js payload is managed via npm and automatically updated by Dependabot.
Dependabot will automatically create PRs when new versions of mermaid are released. The autofix.ci bot will automatically sync the payload file when the PR is created.
For local development, you can manually sync the payload by running npm install in the directory containing the npm configuration for the bundled mermaid.js.
Run the test suite:
cargo test
[!NOTE] Tests require Chrome/Chromium to be installed.
This error means Chrome/Chromium could not be found or launched. Ensure Chrome or Chromium is installed and accessible in your system's PATH.
If you need client-side rendering instead, use the original mdbook-mermaid package.
Server-side rendering adds some overhead to the build process. Each diagram must be rendered in headless Chrome. For large books with many diagrams, this can take additional time. This is a trade-off for the benefits of pre-rendered SVG output.
We have not currently explored parallelization or caching strategies to optimize build times, but would welcome contributions.
MPL. See LICENSE.
Copyright (c) 2018-2024 Jan-Erik Rediger janerik@fnordig.de
This is a fork focusing on server-side rendering only.
Mermaid is MIT licensed.
The bundled assets (payload/mermaid.js) are MIT licensed.