MkDocs plugin to convert Drawio files to SVG format
Project description
MkDocs Drawio Converter Plugin
A MkDocs plugin that automatically converts Draw.io (.drawio) files to SVG format during the build process. The plugin supports both direct links to Draw.io files and image embeds, with support for multi-page Draw.io documents.
Features
- Automatic conversion of Draw.io files to SVG format
- Support for both image embeds and direct links
- Multi-page Draw.io document support
- File caching for improved build performance
- Configurable output formats
- Customizable image and link embedding formats
- Docker-based conversion support
Installation
Prerequisites
- Install Docker on your system
- Pull the Draw.io export Docker image:
docker pull rlespinasse/drawio-export
Plugin Installation
Install the plugin using pip:
pip install mkdocs-drawio-converter
Configuration
Add the plugin to your mkdocs.yml:
plugins:
- drawio-converter:
cache_dir: .drawio-cache # Cache directory for converted files
format: svg # Output format (svg, png, etc.)
embed_format: '<img alt="{img_alt}" src="{img_src}">' # Format for embedding images
link_format: '[{text}]({href})' # Format for direct links
sources: '*.drawio' # Source file pattern
Configuration Options
| Option | Description | Default |
|---|---|---|
cache_dir |
Directory to store converted files | .drawio-cache |
format |
Output format for converted files | svg |
embed_format |
Template for image embeds | <img alt="{img_alt}" src="{img_src}"> |
link_format |
Template for direct links | [{text}]({href}) |
sources |
File pattern for Draw.io files | *.drawio |
Usage
Basic Usage
- Place your Draw.io files in your docs directory
- Reference them in your markdown files:
# As an image

# With a specific page number

# As a direct link
[View Diagram](path/to/diagram.drawio)
Directory Structure Example
docs/
├── diagrams/
│ └── architecture.drawio
├── index.md
└── architecture.md
In your markdown file:
Here's our system architecture:

Multi-page Documents
For Draw.io files with multiple pages, specify the page number using the # syntax:


Build Process
During the MkDocs build:
- The plugin scans markdown files for Draw.io references
- Converts referenced Draw.io files to SVG using Docker
- Updates markdown references to point to converted files
- Caches converted files for future builds
Caching
The plugin maintains a cache of converted files to improve build performance. Files are only reconverted when:
- The source Draw.io file has been modified
- The cache file doesn't exist
- The output format configuration has changed
Docker Conversion
The plugin uses the rlespinasse/drawio-export Docker image for conversion. The conversion process:
- Mounts the source directory in the container
- Converts the Draw.io file to the specified format
- Saves the output to the cache directory
Troubleshooting
Common Issues
-
Docker Not Found
Error: Docker executable not foundSolution: Install Docker and ensure it's running
-
Permission Issues
Error: Permission denied when accessing cache directorySolution: Ensure write permissions for the cache directory
-
File Not Found
Error: Draw.io file not foundSolution: Check file path relative to your docs directory
Debug Logging
Enable debug logging in your mkdocs.yml:
plugins:
- drawio-converter:
# ... other options ...
Add to command:
mkdocs build --verbose
Development
Running Tests
# Install development dependencies
pip install -e ".[test]"
# Run tests
python test_drawio_plugin.py
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
License
This project is licensed under the MIT License - see the LICENSE file for details.
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_drawio_converter-1.1.4.tar.gz.
File metadata
- Download URL: mkdocs_drawio_converter-1.1.4.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67a18e2a1e1702819210df1287ac134624568d870b5fc799417dfc68493d64e6
|
|
| MD5 |
1c38a1f3f3f4b5ddf48a56c7de9eb8cb
|
|
| BLAKE2b-256 |
7910e7b9733efc32be95aefcfc1d9f6c35331ccd0b95ad548b497fe6c8d514e6
|
File details
Details for the file mkdocs_drawio_converter-1.1.4-py3-none-any.whl.
File metadata
- Download URL: mkdocs_drawio_converter-1.1.4-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
829e2cb1e4e6ee6b6bcf62963a1b7bad310c09864ae9028abd778a3965020bca
|
|
| MD5 |
1ebb21a33c93d774ce47b2147b386c6b
|
|
| BLAKE2b-256 |
e31400f27157cd7df6ef8e007fde322a6404c6ab1163a6fe5706659649c462d6
|