Skip to content

Commit

Permalink
Merge pull request #32 from neatc0der/release/v2.2.0
Browse files Browse the repository at this point in the history
Release/v2.2.0
  • Loading branch information
neatc0der authored Nov 4, 2021
2 parents dff5d6a + d11fd64 commit f6bfc8f
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Prepare Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Install Dependencies
run: |
Expand All @@ -28,4 +28,4 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TWINE_PASSWORD: ${{ secrets.TWINE_TOKEN }}
run: inv distribute --tag ${GITHUB_REF#refs/*/} --no-dry-run
run: inv distribute --tag v$(python setup.py --version 2> /dev/null) --no-dry-run
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Prepare Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Install Dependencies
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Prepare Python
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Install Dependencies
run: |
Expand Down
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This is a plugin and an extension for [mkdocs](https://github.com/mkdocs/mkdocs/

This plugin was tested with, but is not limited to:

* Python 3.8
* Python 3.9
* mkdocs 1.1

## Quickstart
Expand Down Expand Up @@ -73,7 +73,7 @@ plugins:
encoding: utf-8
file_extension: .mm.md
d3_version: 6.7.0
lib_version: 0.11.5
lib_version: 0.11.6
view_version: 0.2.6
```
Expand All @@ -82,7 +82,7 @@ In addition, feel free to define your favourite source urls like this:
```yaml
extra_javascript:
- https://unpkg.com/[email protected]/dist/d3.min.js
- https://unpkg.com/[email protected].5/dist/browser/index.min.js
- https://unpkg.com/[email protected].6/dist/browser/index.min.js
- https://unpkg.com/[email protected]/dist/index.min.js
```
Expand All @@ -92,6 +92,15 @@ extra_javascript:
* `markmap-lib`
* `markmap-view`
## Troubleshooting
### Nav tree lists markmaps
1. Move your markmap files to a separate folder next to `docs`, e.g. `mindmaps`
2. Configure `base_path` accordingly (see [Advanced Settings](#advanced-settings))
## Credits :clap:
Some of the development approaches are based on implementations provided by the following projects:
Expand Down
5 changes: 5 additions & 0 deletions changelog/v2.2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# v2.2.0

* 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
2 changes: 1 addition & 1 deletion mkdocs_markmap/__meta__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
PACKAGE_NAME = 'mkdocs_markmap'
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
PROJECT_VERSION = '2.1.3'
PROJECT_VERSION = '2.2.0'

OWNER = 'neatc0der'
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'
2 changes: 1 addition & 1 deletion mkdocs_markmap/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class JsModuleConfig(object):
)

MARKMAP_LIB: JsModuleConfig = JsModuleConfig(
version='0.11.5',
version='0.11.6',
uri='https://unpkg.com/markmap-lib@{}/dist/browser/index.min.js',
)

Expand Down
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();
})();
1 change: 0 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ def get_requirements(filename: str, base_dir: str = 'requirements') -> List[str]
license='MIT',
python_requires='>=3.6',
install_requires=get_requirements('prod.txt'),
setup_requirements=get_requirements('build.txt'),
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
Expand Down

0 comments on commit f6bfc8f

Please sign in to comment.