This is a MkDocs plugin to embed Kroki-Diagrams into your documentation.
Install the plugin using pip:
pip install mkdocs-kroki-plugin
Activate the plugin in mkdocs.yml:
plugins:
...
- kroki:| Key | Description | Default |
|---|---|---|
server_url |
URL of your kroki-Server | !ENV [KROKI_SERVER_URL, 'https://kroki.io'] |
fence_prefix |
Diagram prefix, set to an empty string to render all diagrams using Kroki | kroki- |
enable_block_diag |
Enable BlockDiag (and the related Diagrams) | true |
enable_bpmn |
Enable BPMN | true |
enable_excalidraw |
Enable Excalidraw | true |
enable_mermaid |
Enable Mermaid | true |
enable_diagramsnet |
Enable diagrams.net (draw.io) | false |
http_method |
Http method to use (GET or POST)Note: On POST the retrieved images are stored next to the including page in the build directory |
GET |
request_timeout |
Timeout for HTTP requests in seconds. Increase this value if you encounter timeouts with large diagrams or overloaded kroki server instances. | 30 |
user_agent |
User agent for requests to the kroki server | kroki.plugin/<version> |
file_types |
File types you want to use Note: not all file formats work with all diagram types https://kroki.io/#support |
[svg] |
file_type_overrides |
Overrides for specific diagram types to set the desired file type | [] |
tag_format |
How the image will be included in the resulting HTML (img, object, svg) |
img |
fail_fast |
Errors are raised as plugin errors | false |
cache_dir |
Custom directory for caching rendered diagrams By default uses $XDG_CACHE_HOME/kroki, ~/.cache/kroki, or temp directory |
(automatic) |
Example:
- kroki:
server_url: !ENV [ KROKI_SERVER_URL, 'https://kroki.io' ]
file_types:
- png
- svg
file_type_overrides:
mermaid: png
fail_fast: !ENV CIThe plugin automatically caches rendered diagrams to improve build performance, especially useful during mkdocs serve
when diagrams would otherwise be re-rendered on every file save.
Note: Caching only applies when using http_method: POST. The GET method generates URLs pointing to the Kroki server
and doesn't download diagram content.
How it works:
- Diagrams are cached based on their content, type, format, and options
- Unchanged diagrams are retrieved from cache instead of being re-rendered
- Both in-memory and file-based caching are used for optimal performance
- LRU strategy: Frequently accessed diagrams stay in cache, unused ones expire after 3 days
- Cache cleanup runs automatically on plugin initialization with minimal overhead
Cache location (fallback hierarchy):
$XDG_CACHE_HOME/kroki(if XDG_CACHE_HOME is set)~/.cache/kroki(if HOME is set)- System temp directory +
/kroki(final fallback) - Custom location: Set
cache_dirin plugin configuration to override
Example with custom cache directory:
- kroki:
cache_dir: .cache/kroki # Store cache in project directoryUse code-fences with a tag of kroki-<Module> to replace the code with the wanted diagram.
Diagram options can be set as well.
Example for BlockDiag:
```kroki-blockdiag no-transparency=false
blockdiag {
blockdiag -> generates -> "block-diagrams";
blockdiag -> is -> "very easy!";
blockdiag [color = "greenyellow"];
"block-diagrams" [color = "pink"];
"very easy!" [color = "orange"];
}
```You can render diagram from file with @from_file: directive:
```kroki-bpmn
@from_file:path/to/diagram.bpmn
```Want to appear in the list of contributors?
Get started by reading the Contribution Guidelines
Diagram examples can be found here.
More information about installing a self-manged Kroki-Service here.
More Plugins for MkDocs can be found here
Install the newest pre-release version using pip:
pip install -i https://test.pypi.org/simple/ mkdocs-kroki-plugin
git clone git@github.com:AVATEAM-IT-SYSTEMHAUS/mkdocs-kroki-plugin.git
cd mkdocs-kroki-plugin
uv syncInstall the pre-commit hooks to run linting, type checking, and tests automatically on commit:
uv run pre-commit installTo run all hooks manually:
uv run pre-commit run --all-filesRun tests:
uv run pytestRun tests with coverage:
uv run pytest --covRun ruff for linting and formatting:
uv run ruff check .
uv run ruff format .Run mypy:
uv run --group types mypy krokiUse the release script to create a new version:
./release.py <version>For example:
./release.py 1.2.3The script will:
- Validate the version format (semantic versioning: X.Y.Z)
- Check that the working tree is clean
- Update the
__version__inkroki/__init__.py - Create a commit:
chore: Bump version to X.Y.Z - Create an annotated git tag:
vX.Y.Z - Push the commit and tag to GitHub
- Open your browser to create a GitHub release where you can add the changelog
Requirements:
- Clean working tree (no uncommitted changes)
- Version must follow semantic versioning format (e.g., 1.2.3)