From 9450ea8cdb815d066b6e9d4b59be163612eae358 Mon Sep 17 00:00:00 2001 From: Jan Larwig Date: Thu, 18 Jun 2026 12:07:13 +0200 Subject: [PATCH] fix: viewer js relativ url handling for versioning support using mike Signed-off-by: Jan Larwig --- README.md | 2 ++ examples/docs/configuration.md | 2 ++ mkdocs_drawio/plugin.py | 4 ++-- pyproject.toml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index b1485a5..4508154 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,8 @@ By default the plugin uses the official url for the minified drawio javascript l > If you want to use a self-hosted JavaScript viewer file. You should download the latest version from the [official drawio repo](https://github.com/jgraph/drawio/blob/dev/src/main/webapp/js/viewer-static.min.js). +Self-hosted viewer paths can be configured as site-root paths such as `/js/viewer-static.min.js`. The plugin normalizes them per page, so they also work on versioned deployments such as `mike`. + ```yaml plugins: - drawio: diff --git a/examples/docs/configuration.md b/examples/docs/configuration.md index e5ec1df..3e738d9 100644 --- a/examples/docs/configuration.md +++ b/examples/docs/configuration.md @@ -4,6 +4,8 @@ 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. +Self-hosted viewer paths can be configured as site-root paths such as `/js/viewer-static.min.js`. The plugin normalizes them per page, so they also work on versioned deployments such as `mike`. + ```yaml plugins: - drawio: diff --git a/mkdocs_drawio/plugin.py b/mkdocs_drawio/plugin.py index 9f43a76..91cfa2f 100644 --- a/mkdocs_drawio/plugin.py +++ b/mkdocs_drawio/plugin.py @@ -9,7 +9,7 @@ from pathlib import Path from typing import Dict from bs4 import BeautifulSoup -from mkdocs.utils import copy_file +from mkdocs.utils import copy_file, normalize_url from mkdocs.plugins import BasePlugin from mkdocs.config import base, config_options as c @@ -164,7 +164,7 @@ def render_drawio_diagrams(self, output_content, page): return output_content # add drawio library to body - lib = soup.new_tag("script", src=self.config.viewer_js) + lib = soup.new_tag("script", src=normalize_url(self.config.viewer_js, page)) soup.body.append(lib) # substitute images with embedded drawio diagram diff --git a/pyproject.toml b/pyproject.toml index d7abeb4..2b48515 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "mkdocs-drawio" -version = "1.16.1" +version = "1.16.2" description = "MkDocs plugin for embedding Drawio files" authors = [ "Jan Larwig ",