MkDocs Plugin for embedding Drawio files

Buy Sergey a ☕
Sergey (onixpro) is the original creator of this plugin. Repo can be found here.
Features
This plugin enables you to embed interactive drawio diagrams in your documentation. Simply add your diagrams like you would any other image:
You can either use diagrams hosted within your own docs. Absolute as well as relative paths are allowed:
Absolute path:

Same directory as the markdown file:

Relative directory to the markdown file:

Or you can use external urls:

Additionally this plugin supports multi page diagrams by using the alt
text to select the pages by name:


Setup
Install plugin using pip:
pip install mkdocs-drawio
Add the plugin to your mkdocs.yml
plugins:
- drawio
Configuration Options
By default the plugin uses the official url for the minified drawio javascript library. To use a custom source for the drawio viewer you can overwritte the url. This might be useful in airlocked environments.
If you want to use a self-hosted JavaScript viewer file. You should download the latest version from the official drawio repo.
plugins:
- drawio:
viewer_js: "https://viewer.diagrams.net/js/viewer-static.min.js"
Further options are:
plugins:
- drawio:
toolbar: true
tooltips: true
edit: true
border: 10
Material Integration
If you are using the Material Theme and want to use the instant-loading feature. You will have to configure the following:
In your mkdocs.yaml
:
theme:
name: material
features:
- navigation.instant
plugins:
- drawio
extra_javascript:
- https://viewer.diagrams.net/js/viewer-static.min.js
- javascripts/drawio-reload.js
Add docs/javascripts/drawio-reload.js
to your project:
document$.subscribe(({ body }) => {
GraphViewer.processElements()
})
How it works
- mkdocs generates the html per page
mkdocs-drawio
attaches to the on_post_page
event. For more details, please have a look at the event lifecycle documentation- Adds the drawio viewer library
- Searches through the generated html for all
img
tags that have a source of type .drawio
- Replaces the found
img
tags with mxgraph
html blocks (actual drawio diagram content). For more details, please have a look at the official drawio.com documentation.
Contribution guide
- Setup a virtual environment:
python3 -m venv venv && source venv/bin/activate
- Install poetry:
pip install poetry
- Install dependencies and current version:
poetry install
- Make your desired changes
- Add a test for your changes in the
example
directory - Test your changes by starting
mkdocs serve
in the example
directory - Increase the version in
pyproject.toml
- Make sure
poetry run ruff check .
and poetry run black --check .
passing - Open your pull request ✨️