Skip to content

Commit

Permalink
fix: render markmaps in SPA
Browse files Browse the repository at this point in the history
and fix compatibility issue with mkdocs-material

close #42
  • Loading branch information
gera2ld authored Oct 4, 2023
1 parent 35e4776 commit dec0c9e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
24 changes: 12 additions & 12 deletions mkdocs_markmap/static_files/mkdocs-markmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
})();

0 comments on commit dec0c9e

Please sign in to comment.