Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.x"
- name: Install poetry
run: python3 -m pip install build poetry --user

- name: Set up uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0

- name: Install dependencies
run: poetry install --no-root
run: uv sync --group dev

- name: Check formatting
run: |
poetry run ruff check .
poetry run black --check .
uv run ruff check .
uv run black --check .

- name: Test the build
run: poetry build
- name: Test the build
run: uv build
18 changes: 7 additions & 11 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,17 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Configure Git Credentials
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
- uses: actions/setup-python@v5
- uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: 3.x
- name: Build mkdocs-drawio
run: |
pip install poetry
poetry install
- name: Set up uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
- name: Install dependencies
run: uv sync --group dev
- name: Build and publish docs
run: |
cd examples
source $(poetry env info --path)/bin/activate
pip install -r requirements.txt
mkdocs gh-deploy --force
run: uv run mkdocs gh-deploy --config-file examples/mkdocs.yml --force
33 changes: 15 additions & 18 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ jobs:
id-token: write

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: "3.x"
- name: Install poetry
run: python3 -m pip install build poetry --user

- name: Set up uv
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0

- name: Install dependencies
run: poetry install --no-root
run: uv sync --group dev

- name: Check formatting
run: |
poetry run ruff check .
poetry run black --check .
uv run ruff check .
uv run black --check .

- name: Build
run: poetry build
run: uv build

- name: Store the distribution packages
uses: actions/upload-artifact@v4
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: python-package-distributions
path: dist/
Expand All @@ -51,7 +51,7 @@ jobs:
git config --local user.name "github-actions[bot]"
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"

tag="v$(poetry version -s)"
tag="v$(python -c "import tomllib; print(tomllib.load(open('pyproject.toml', 'rb'))['project']['version'])")"

git tag -a "${tag}" -m "Release ${tag}"
git push origin "${tag}"
Expand All @@ -61,9 +61,6 @@ jobs:
--title="${tag}" \
--generate-notes

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

publish:
needs:
- build
Expand All @@ -73,9 +70,9 @@ jobs:

steps:
- name: Download all the dists
uses: actions/download-artifact@v4
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: python-package-distributions
path: dist/
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
uses: pypa/gh-action-pypi-publish@2834a314042ef964da07689278dd1e9d773e8afd # v1.14.1
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
[![PyPI](https://img.shields.io/pypi/v/mkdocs-drawio)](https://pypi.org/project/mkdocs-drawio/)
![PyPI - Downloads](https://img.shields.io/pypi/dm/mkdocs-drawio)

Sergey ([onixpro](https://github.com/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 ☕](https://www.buymeacoffee.com/SergeyLukin)
See the [official docs](https://tuunit.github.io/mkdocs-drawio/) and the [live example page](https://tuunit.github.io/mkdocs-drawio/tests/simple-diagram/).

## Features

Expand Down Expand Up @@ -44,12 +43,18 @@ Or use the page attribute:

## Setup

Install plugin using pip:
Install the plugin with pip:

```bash
pip install mkdocs-drawio
```

If you are managing your MkDocs project with uv, use:

```bash
uv add mkdocs-drawio
```

Add the plugin to your `mkdocs.yml`

```yaml
Expand Down Expand Up @@ -163,12 +168,16 @@ Its a bit of a workaround as it listens for all events on the page and retrigger

## Contribution guide

1. Setup a virtual environment: `python3 -m venv venv && source venv/bin/activate`
2. Install poetry: `pip install poetry`
3. Install dependencies and current version: `poetry install`
4. Make your desired changes
5. Add a test for your changes in the `example` directory
6. Test your changes by starting `mkdocs serve` in the `example` directory
7. Increase the version in `pyproject.toml`
8. Make sure `poetry run ruff check .` and `poetry run black --check .` passing
9. Open your pull request ✨️
1. Install uv and use Python 3.9 or newer.
2. Install dependencies and the current project: `uv sync --group dev`
3. Make your desired changes.
4. Add a test for your changes in the `examples` directory.
5. Test your changes with `uv run mkdocs serve -f examples/mkdocs.yml`
6. Increase the version in `pyproject.toml`.
7. Make sure `uv run ruff check .` and `uv run black --check .` pass.
8. Open your pull request ✨️

## Project History

Sergey ([onixpro](https://github.com/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 ☕](https://www.buymeacoffee.com/SergeyLukin)
16 changes: 10 additions & 6 deletions examples/docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

This plugin allows you to embed draw.io diagrams in your MkDocs documentation. It is compatible with most MkDocs themes, but specifically tested with the Material theme and the MkDocs default theme.

Sergey ([onixpro](https://github.com/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 ☕](https://www.buymeacoffee.com/SergeyLukin)
<img width="256" height="256" alt="Image" src="https://github.com/user-attachments/assets/fb25d409-38eb-4e1a-90e8-6db78999514e" />

## Installation

Install the plugin using pip or poetry:
Install the plugin with pip:

```bash
pip install mkdocs-drawio
```

or
If you are managing your MkDocs project with uv, use:

```bash
poetry add mkdocs-drawio
uv add mkdocs-drawio
```

Then add the plugin to your `mkdocs.yml`:
Expand All @@ -39,7 +38,6 @@ The currently supported features are:

## Usage


Simply add an image as you would normally do in markdown:

```markdown
Expand All @@ -63,3 +61,9 @@ Additionally this plugin supports multi page diagrams by using the `alt` text to
![Page-2](my-diagram.drawio)
![my-custom-page-name](my-diagram.drawio)
```


## Project History

Sergey ([onixpro](https://github.com/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 ☕](https://www.buymeacoffee.com/SergeyLukin)
3 changes: 0 additions & 3 deletions examples/requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion mkdocs_drawio/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .plugin import DrawioPlugin

__all__ = [DrawioPlugin]
__all__ = ["DrawioPlugin"]
50 changes: 26 additions & 24 deletions mkdocs_drawio/plugin.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import re
from __future__ import annotations

import json
import string
import png
import logging
from lxml import etree
import re
import string
from html import escape
from urllib.parse import unquote
from pathlib import Path
from typing import Dict
from urllib.parse import unquote

import png
from bs4 import BeautifulSoup
from mkdocs.utils import copy_file, normalize_url
from lxml import etree
from mkdocs.config import base
from mkdocs.config import config_options as c
from mkdocs.plugins import BasePlugin
from mkdocs.config import base, config_options as c
from mkdocs.utils import copy_file, normalize_url

SUB_TEMPLATE = string.Template(
'<div class="mxgraph" style="max-width:100%;border:1px solid transparent;$style" data-mxgraph="$config"></div>'
Expand Down Expand Up @@ -89,7 +92,7 @@ class DrawioPlugin(BasePlugin[DrawioConfig]):
Plugin for embedding Drawio Diagrams into your MkDocs
"""

def get_diagram_config(self) -> Dict:
def get_diagram_config(self) -> dict:
"""Build diagram config using only global plugin settings."""

toolbar_items = []
Expand Down Expand Up @@ -127,18 +130,17 @@ def get_toolbar_config(self, toolbar_config) -> Toolbar:
config = Toolbar()

# Bool means enable defaults or disable completely.
if isinstance(toolbar_config, bool):
if toolbar_config is False:
# Flip all toolbar items off but keep other defaults intact.
for key in (
"pages",
"tags",
"zoom",
"layers",
"lightbox",
"show_title",
):
setattr(config, key, False)
if isinstance(toolbar_config, bool) and toolbar_config is False:
# Flip all toolbar items off but keep other defaults intact.
for key in (
"pages",
"tags",
"zoom",
"layers",
"lightbox",
"show_title",
):
setattr(config, key, False)

if isinstance(toolbar_config, dict):
# Load values through mkdocs config validation to respect defaults.
Expand Down Expand Up @@ -209,7 +211,7 @@ def render_drawio_diagrams(self, output_content, page):
diagram_page,
diagram_style,
)
except Exception as e:
except (OSError, ValueError, etree.LxmlError) as e:
LOGGER.error(
f"Error: Could not parse diagram file '{diagram['src']}' on path '{path}': {e}"
)
Expand Down Expand Up @@ -257,14 +259,14 @@ def retrieve_mxfile(
return etree.fromstring(xml_data.encode())

@staticmethod
def substitute_with_url(config: Dict, url: str, style: str) -> str:
def substitute_with_url(config: dict, url: str, style: str) -> str:
config["url"] = url

return SUB_TEMPLATE.substitute(config=escape(json.dumps(config)), style=style)

@staticmethod
def substitute_with_file(
mxfile_xml: etree._Element, config: Dict, page: str, style: str
mxfile_xml: etree._Element, config: dict, page: str, style: str
) -> str:
if mxfile_xml is not None:
diagram = DrawioPlugin.parse_diagram(mxfile_xml, page)
Expand Down
Loading