Skip to content

Commit

Permalink
Merge pull request #30 from neatc0der/feature/encryptcontent
Browse files Browse the repository at this point in the history
feature/encryptcontent
  • Loading branch information
neatc0der authored Nov 4, 2021
2 parents f27131e + e21f08e commit d11fd64
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
3 changes: 2 additions & 1 deletion changelog/v2.2.0.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# v2.2.0

* Fixes distribute workflow
* Adds [support for mkdocs-encryptcontent-plugin](https://github.com/neatc0der/mkdocs-markmap/issues/26)
* Adds troubleshooting for [nav tree lists markmap files](https://github.com/neatc0der/mkdocs-markmap/issues/33)
* Fixes distribute workflow
18 changes: 11 additions & 7 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,24 @@ def on_config(self, config: Config) -> Config:

return config

def on_post_page(self, output_content: str, config: Config, **kwargs) -> str:
soup: BeautifulSoup = BeautifulSoup(output_content, 'html.parser')
page: Page = kwargs.get('page')

markmaps: ResultSet = soup.find_all(class_='language-markmap')
if not any(markmaps):
def on_post_page(self, html: str, page: Page, config: Config, **kwargs) -> str:
if not getattr(page, '_found_markmap', False):
log.info(f"no markmap found: {page.file.name}")
return output_content
return html

soup: BeautifulSoup = BeautifulSoup(html, 'html.parser')
script_base_url: str = re.sub(r'[^/]+?/', '../', re.sub(r'/+?', '/', page.url)) + 'js/'
js_path: Path = Path(config['site_dir']) / 'js'
self._load_scripts(soup, script_base_url, js_path)
self._add_statics(soup)

return str(soup)

def on_page_content(self, html: str, page: Page, **kwargs) -> str:
soup: BeautifulSoup = BeautifulSoup(html, 'html.parser')
markmaps: ResultSet = soup.find_all(class_='language-markmap')
setattr(page, '_found_markmap', any(markmaps))

for index, markmap in enumerate(markmaps):
markmap: Tag
tag_id: str = f'markmap-{index}'
Expand Down
44 changes: 29 additions & 15 deletions mkdocs_markmap/static_files/mkdocs-markmap.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
(function initializeMarkmap() {
const markmap_transformer = new markmap.Transformer();
const markmaps = document.getElementsByClassName('mkdocs-markmap');
var el, content, svg, root, m;
for (var i = 0; i < markmaps.length; i++) {
el = markmaps[i];
content = el.getAttribute('data-markdown').replaceAll('&#10;', '\n');
svg = el.querySelector('svg');
root = markmap_transformer.transform(content).root;
m = markmap.Markmap.create(svg, null, root);
function update_markmaps() {
const markmap_transformer = new markmap.Transformer();
const markmaps = document.getElementsByClassName('mkdocs-markmap');
var el, content, svg, root, m;
for (var i = 0; i < markmaps.length; i++) {
el = markmaps[i];
content = el.getAttribute('data-markdown').replaceAll('&#10;', '\n');
svg = el.querySelector('svg');
root = markmap_transformer.transform(content).root;
m = markmap.Markmap.create(svg, null, root);

(function(obj, e, r) {
obj.rescale(1).then(function() {
e.parentElement.style.height = (e.getBBox().height + 10) + "px";
requestAnimationFrame(() => { obj.fit(); })
});
})(m, svg, root);
(function(obj, e, r) {
obj.rescale(1).then(function() {
e.parentElement.style.height = (e.getBBox().height + 10) + "px";
requestAnimationFrame(() => { obj.fit(); })
});
})(m, svg, root);
}
}

var MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations) {
update_markmaps();
});

var target = document.getElementById('mkdocs-decrypted-content');
if (undefined != target) {
observer.observe(target, { childList: true });
}

update_markmaps();
})();

0 comments on commit d11fd64

Please sign in to comment.