Skip to main content

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

  1. Install Docker on your system
  2. 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

  1. Place your Draw.io files in your docs directory
  2. Reference them in your markdown files:
# As an image
![Diagram Title](path/to/diagram.drawio)

# With a specific page number
![Diagram Title](path/to/diagram.drawio#0)

# 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:

![Architecture Diagram](diagrams/architecture.drawio#0)

Multi-page Documents

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

![Page 1](diagram.drawio#0)
![Page 2](diagram.drawio#1)

Build Process

During the MkDocs build:

  1. The plugin scans markdown files for Draw.io references
  2. Converts referenced Draw.io files to SVG using Docker
  3. Updates markdown references to point to converted files
  4. 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:

  1. Mounts the source directory in the container
  2. Converts the Draw.io file to the specified format
  3. Saves the output to the cache directory

Troubleshooting

Common Issues

  1. Docker Not Found

    Error: Docker executable not found
    

    Solution: Install Docker and ensure it's running

  2. Permission Issues

    Error: Permission denied when accessing cache directory
    

    Solution: Ensure write permissions for the cache directory

  3. File Not Found

    Error: Draw.io file not found
    

    Solution: 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

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. 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

mkdocs_drawio_converter-1.1.4.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_drawio_converter-1.1.4-py3-none-any.whl (7.6 kB view details)

Uploaded Python 3

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

Hashes for mkdocs_drawio_converter-1.1.4.tar.gz
Algorithm Hash digest
SHA256 67a18e2a1e1702819210df1287ac134624568d870b5fc799417dfc68493d64e6
MD5 1c38a1f3f3f4b5ddf48a56c7de9eb8cb
BLAKE2b-256 7910e7b9733efc32be95aefcfc1d9f6c35331ccd0b95ad548b497fe6c8d514e6

See more details on using hashes here.

File details

Details for the file mkdocs_drawio_converter-1.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_drawio_converter-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 829e2cb1e4e6ee6b6bcf62963a1b7bad310c09864ae9028abd778a3965020bca
MD5 1ebb21a33c93d774ce47b2147b386c6b
BLAKE2b-256 e31400f27157cd7df6ef8e007fde322a6404c6ab1163a6fe5706659649c462d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page