MkDocs plugin for embedding Drawio files
Project description
MkDocs Plugin for embedding Drawio files
Sergey (onixpro) is the original creator of this plugin but since his repository isn't maintained anymore we forked it on the 19th December of 2023 and have been keeping it up-to-date and expanding on the features since then. Buy Sergey a ☕
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 either the page or alt property. To use the page property, you need to use the markdown extension attr_list.
Either use the alt text:


Or use the page attribute:
{ page="Page-2" }
{ page="my-custom-page-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:
tooltips: true # Enable tooltips on diagram elements
border: 5 # Border size / padding around diagrams
edit: true # Enable opening the editor for diagrams
darkmode: true # Enable dark mode support (classic MkDocs and Material)
highlight: "#0000FF" # Highlight color for hyperlinks
lightbox: true # Enable opening the lightbox on click
toolbar: # Control the looks and behaviour of the toolbar
pages: true # Display the page selector
tags: true # Display the tags selector
zoom: true # Display the zoom controls
layers: true # Display the layer controls
lightbox: true # Display the lightbox / fullscreen button
position: "top" # Control the position of the toolbar (top or bottom)
no_hide: false # Do not hide the toolbar when not hovering over diagrams
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()
})
Using Tabs (pymdownx.tabbed)
If you want to use drawio diagrams inside of tabs you need to make sure that the diagrams are processed after the tabs are rendered. You can achieve this by adding the following javascript to your mkdocs.yml:
extra_javascript:
- javascripts/drawio-tabs.js
Add docs/javascripts/drawio-tabs.js to your project:
document.addEventListener('change', (event) => {
// Check if the target is a pymdownx tab input
if (event.target.matches('.tabbed-set > input')) {
GraphViewer.processElements()
}
});
Its a bit of a workaround as it listens for all events on the page and retriggers the drawio processing if any tab is clicked.
How it works
- mkdocs generates the html per page
mkdocs-drawioattaches to theon_post_pageevent. For more details, please have a look at the event lifecycle documentation- Adds the drawio viewer library
- Searches through the generated html for all
imgtags that have a source of type.drawio - Replaces the found
imgtags withmxgraphhtml 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
exampledirectory - Test your changes by starting
mkdocs servein theexampledirectory - Increase the version in
pyproject.toml - Make sure
poetry run ruff check .andpoetry run black --check .passing - Open your pull request ✨️
Project details
Release history Release notifications | RSS feed
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_drawio-1.13.0.tar.gz.
File metadata
- Download URL: mkdocs_drawio-1.13.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fb1a438bf9b61fa60440b5b98d0b4434f58688e3e5a64c27adcaf3612956848
|
|
| MD5 |
8aa9e26b4ad0b766fd4b8ddd82585f86
|
|
| BLAKE2b-256 |
ff6bb565798b969e15e16e2eecfbe19773a91b91eacf1fe5af9a7e1e35bf7a23
|
Provenance
The following attestation bundles were made for mkdocs_drawio-1.13.0.tar.gz:
Publisher:
python-publish.yml on tuunit/mkdocs-drawio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_drawio-1.13.0.tar.gz -
Subject digest:
0fb1a438bf9b61fa60440b5b98d0b4434f58688e3e5a64c27adcaf3612956848 - Sigstore transparency entry: 810187713
- Sigstore integration time:
-
Permalink:
tuunit/mkdocs-drawio@68f381cd68f959afc1caedf747765cfd0e9de0de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tuunit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@68f381cd68f959afc1caedf747765cfd0e9de0de -
Trigger Event:
push
-
Statement type:
File details
Details for the file mkdocs_drawio-1.13.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_drawio-1.13.0-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1393ff45f3087a56014b732df0863b76291e5f4390840435c734d5098ec81b8a
|
|
| MD5 |
6312da7a794e9fec3159b03136500b62
|
|
| BLAKE2b-256 |
0eb9624283d6dea533c6b1b0bdea8acdf20a47f62a05db1ce8710331f74a0795
|
Provenance
The following attestation bundles were made for mkdocs_drawio-1.13.0-py3-none-any.whl:
Publisher:
python-publish.yml on tuunit/mkdocs-drawio
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_drawio-1.13.0-py3-none-any.whl -
Subject digest:
1393ff45f3087a56014b732df0863b76291e5f4390840435c734d5098ec81b8a - Sigstore transparency entry: 810187716
- Sigstore integration time:
-
Permalink:
tuunit/mkdocs-drawio@68f381cd68f959afc1caedf747765cfd0e9de0de -
Branch / Tag:
refs/heads/main - Owner: https://github.com/tuunit
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@68f381cd68f959afc1caedf747765cfd0e9de0de -
Trigger Event:
push
-
Statement type: