MkDocs plugin that renders Mermaid fences to hashed PNG assets
Project description
mkdocs-mermaid-images
MkDocs plugin that replaces Mermaid code fences with generated PNG images.
Basic setup
Add the plugin to your mkdocs.yml:
site_name: My Docs
plugins:
- search
- mermaid-images
Requirements
You do not need to install @mermaid-js/mermaid-cli globally. The plugin runs it through npx when MkDocs builds the site.
That means the machine running the build needs:
nodeandnpxavailable onPATH- network access on the first run so
npxcan fetch@mermaid-js/mermaid-cliif it is not already cached - any system dependencies required by Mermaid CLI's headless browser on that platform
For locked-down Linux CI environments, you may also need to disable Chromium sandboxing. The demo site does this with no_sandbox: !ENV [MKDOCS_MERMAID_IMAGES_NO_SANDBOX, false], and the GitHub Actions workflow sets that environment variable only in CI.
Examples
Use either mermaid or mermaidjs fenced code blocks in Markdown:
# Architecture
```mermaid
flowchart TD
User --> MkDocs
MkDocs --> Plugin
Plugin --> PNG[Generated PNG]
```
The built page will contain a normal Markdown image link instead of the code fence, and the generated file will be written under assets/mermaid/.
Repeated diagrams are rendered once and reused by content hash:
```mermaid
graph TD
A --> B
```
```mermaid
graph TD
A --> B
```
Both fences will point at the same generated PNG.
You can also use mermaidjs fences:
~~~mermaidjs
sequenceDiagram
participant User
participant Site
User->>Site: Open docs
~~~
For CI environments that require Chromium sandboxing to be disabled:
plugins:
- mermaid-images:
no_sandbox: !ENV [MKDOCS_MERMAID_IMAGES_NO_SANDBOX, false]
If you already have a Puppeteer config file, you can pass it through to Mermaid CLI:
plugins:
- mermaid-images:
puppeteer_config_file: puppeteer-config.json
Demo site
A minimal demo site lives in examples/demo. It has a single page with a few Mermaid diagrams so you can verify the plugin renders them into image assets during the build.
Run it from the repository root:
uv sync
uv run mkdocs serve -f examples/demo/mkdocs.yml
Or use the Makefile targets:
make demo-serve
Or build the static site:
uv run mkdocs build -f examples/demo/mkdocs.yml
You can also run the repository checks from the root:
make ty
make test
make check
The generated files will be written to examples/demo/site/, and the rendered diagram images will appear under examples/demo/site/assets/mermaid/.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mkdocs_mermaid_images-0.2.0.tar.gz.
File metadata
- Download URL: mkdocs_mermaid_images-0.2.0.tar.gz
- Upload date:
- Size: 38.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40fe17c7e1d743317e6dd15fc357de54b01c87e4a075a7a7336c9ac61ead7be7
|
|
| MD5 |
a42998da5e0e1bc1c7a1619dadff8f07
|
|
| BLAKE2b-256 |
190de3068a1a774b475e833ed4aa707e8bd7c7476b4fdfee1723bfa844ce1659
|
File details
Details for the file mkdocs_mermaid_images-0.2.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_mermaid_images-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84313e5d90e48c508f1185e63b7b29ef354d0c953d03a8a7b444c83e60700059
|
|
| MD5 |
c1a4bafce6efe231468347473ca9dcf0
|
|
| BLAKE2b-256 |
9ce30d1afa146cd82c1a4c29a17d21363e467f85cbc0b4b5d7beac4963b080a1
|