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)) 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" 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); }); })(); 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