MkDocs Kroki Plugin
mkdocs-kroki-plugin is an MkDocs plugin designed to embed Kroki-Diagrams directly into your documentation. It is currently at version 1.6.0 and maintains an active development cycle, releasing new features, bug fixes, and improvements frequently, as seen in its recent series of minor and patch releases.
Common errors
-
Broken images or missing diagrams in Backstage TechDocs site after upgrade.
cause Specific issues with how Backstage TechDocs handles local asset paths or `object` tags generated by the plugin in older versions. For example, `0.8.1` switched to `<object>` tags which caused problems for Backstage.fixUpgrade `mkdocs-kroki-plugin` to the latest version. If using `mkdocs-techdocs-core`, ensure it's also updated. Check for configuration regarding `tag_format` (default `img` is usually more compatible than `object` or `svg` in some environments) and `http_method: POST` for downloading images. -
Diagrams are not displayed at all, just showing the code fence.
cause Incorrect plugin activation in `mkdocs.yml`, a non-reachable Kroki server, syntax errors in the diagram code, or a regex parsing issue in older versions.fixVerify the plugin is correctly listed under `plugins:` in `mkdocs.yml`. Check that your diagram syntax is valid for the specified Kroki type. Ensure the `server_url` is correct and reachable (default is `https://kroki.io`). Upgrade to the latest plugin version to address parsing fixes. -
MkDocs build fails with 'KeyError' or 'TypeError' related to plugin configuration after update.
cause This typically occurs after upgrading to v1.0.0 where configuration option names changed from PascalCase to snake_case and some options were removed.fixUpdate your `mkdocs.yml` to use the new snake_case configuration keys (e.g., `server_url` instead of `ServerURL`) and remove any deprecated configuration options. Refer to the plugin's documentation for the updated config schema. -
HTTP timeout errors when rendering large diagrams.
cause The default HTTP request timeout to the Kroki server might not be sufficient for complex or large diagrams that take longer to process.fixIncrease the `request_timeout` option in your `mkdocs.yml` plugin configuration (e.g., `request_timeout: 60`). `server_url: !ENV [KROKI_SERVER_URL, 'https://kroki.io']`
Warnings
- breaking Configuration options were renamed and deprecated options removed in v1.0.0 to align with MkDocs conventions. For example, `ServerURL` became `server_url`, and options like `Enablebpmn` or `DownloadImages` were removed.
- gotcha The plugin's documentation suggests considering migration to ProperDocs, a fork of MkDocs, which may simplify future updates.
- gotcha Theme-aware styles (`styles_light`, `styles_dark`) for diagrams require `http_method: POST` and `tag_format: img` to function correctly, particularly with themes like Material for MkDocs. Other `tag_format` settings (`object`, `svg`) will fall back to light-mode styles only with a warning.
- gotcha Older versions (prior to v1.6.0) might incorrectly skip diagrams that appear after code blocks with unrecognized attributes due to a fence regex issue.
- gotcha When running a local Kroki server via Docker, its default port (often 8000) can conflict with `mkdocs serve`'s default port, leading to startup issues.
Install
-
pip install mkdocs-kroki-plugin
Imports
- KrokiPlugin
from kroki.plugin import KrokiPlugin
Quickstart
# mkdocs.yml
site_name: My Docs with Kroki
plugins:
- kroki:
server_url: https://kroki.io # Optional, default is https://kroki.io
# docs/index.md
# Example BlockDiag diagram
```kroki-blockdiag
blockdiag {
blockdiag -> generates -> "block-diagrams";
blockdiag -> is -> "very easy!";
blockdiag [color = "greenyellow"];
"block-diagrams" [color = "pink"];
"very easy!" [color = "orange"];
}
```
# To run:
# mkdocs serve