From dec0c9ecef1322ae3c8828ca37c63f1dac758431 Mon Sep 17 00:00:00 2001 From: Gerald Date: Wed, 4 Oct 2023 14:46:32 +0800 Subject: [PATCH 1/4] fix: render markmaps in SPA and fix compatibility issue with mkdocs-material close #42 --- mkdocs_markmap/plugin.py | 4 ++-- mkdocs_markmap/static_files/mkdocs-markmap.js | 24 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/mkdocs_markmap/plugin.py b/mkdocs_markmap/plugin.py index b7f00e5..b11239e 100644 --- a/mkdocs_markmap/plugin.py +++ b/mkdocs_markmap/plugin.py @@ -127,7 +127,7 @@ def on_page_content(self, html: str, page: Page, **kwargs) -> str: code = markmap pre.name = "div" pre["class"] = pre.get("class", []) + ["mkdocs-markmap"] - code.name = "script" - code["type"] = "text/template" + code.name = "markmap-data" + code.attrs["hidden"] = "true" return str(soup) diff --git a/mkdocs_markmap/static_files/mkdocs-markmap.js b/mkdocs_markmap/static_files/mkdocs-markmap.js index 048bcae..3715fc7 100644 --- a/mkdocs_markmap/static_files/mkdocs-markmap.js +++ b/mkdocs_markmap/static_files/mkdocs-markmap.js @@ -38,25 +38,25 @@ }); } - function updateMarkmaps() { - const markmaps = document.getElementsByClassName('mkdocs-markmap'); - for (var i = 0; i < markmaps.length; i++) { - const el = markmaps[i]; + function updateMarkmaps(node) { + for (const el of node.querySelectorAll('.mkdocs-markmap')) { renderMarkmap(el); } } loading.then(() => { - var MutationObserver = window.MutationObserver || window.WebKitMutationObserver; - var observer = new MutationObserver(function(mutations) { - updateMarkmaps(); + const observer = new MutationObserver((mutationList) => { + for (const mutation of mutationList) { + if (mutation.type === 'childList') { + for (const node of mutation.addedNodes) { + updateMarkmaps(node); + } + } + } }); - var target = document.getElementById('mkdocs-decrypted-content'); - if (undefined != target) { - observer.observe(target, { childList: true }); - } + observer.observe(document.body, { childList: true }); - updateMarkmaps(); + updateMarkmaps(document); }); })(); From a2c4c0c0b96c49fb988dc1b71f7c3faaf6a23e67 Mon Sep 17 00:00:00 2001 From: neatc0der <2805028+neatc0der@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:04:32 +0200 Subject: [PATCH 2/4] Ease dependency to attrs --- requirements/prod.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/prod.txt b/requirements/prod.txt index 4f09ec2..5cfc07e 100644 --- a/requirements/prod.txt +++ b/requirements/prod.txt @@ -1,5 +1,5 @@ mkdocs>=1.3,<2 -attrs==20.3.0 +attrs>=20.3.0 beautifulsoup4>=4.6.3 requests<3 From c5f252e07fe35147dca0ec104f08e7b05d96ee21 Mon Sep 17 00:00:00 2001 From: neatc0der <2805028+neatc0der@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:13:07 +0200 Subject: [PATCH 3/4] Add changelog for v2.4.2 --- changelog/v2.4.2.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 changelog/v2.4.2.md diff --git a/changelog/v2.4.2.md b/changelog/v2.4.2.md new file mode 100644 index 0000000..e16649d --- /dev/null +++ b/changelog/v2.4.2.md @@ -0,0 +1,4 @@ +# v2.4.2 + +* Relaxes dependency to `attrs` (see [#47](https://github.com/markmap/mkdocs-markmap/issues/47)) +* Fix for rendering in SPA (see [#42](https://github.com/markmap/mkdocs-markmap/issues/42)) From 2921de6f5853927c2dcf438a4a9c7997be229173 Mon Sep 17 00:00:00 2001 From: neatc0der <2805028+neatc0der@users.noreply.github.com> Date: Thu, 5 Oct 2023 17:13:38 +0200 Subject: [PATCH 4/4] Bump version to v2.4.2 --- mkdocs_markmap/__meta__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mkdocs_markmap/__meta__.py b/mkdocs_markmap/__meta__.py index 339620e..a75d0ab 100644 --- a/mkdocs_markmap/__meta__.py +++ b/mkdocs_markmap/__meta__.py @@ -1,6 +1,6 @@ PACKAGE_NAME: str = "mkdocs_markmap" PROJECT_NAME: str = PACKAGE_NAME.replace("_", "-") -PROJECT_VERSION: str = "2.4.1" +PROJECT_VERSION: str = "2.4.2" OWNER: str = "neatc0der" ORGANISATION: str = "markmap"