Skip to content

Commit

Permalink
Merge pull request #25 from neatc0der/release/v2.1.2
Browse files Browse the repository at this point in the history
Release/v2.1.2
  • Loading branch information
neatc0der authored Sep 18, 2021
2 parents 229b4c5 + 7c3e805 commit 05c8fe5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/distribute.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
name: Distribution Workflow

on:
workflow_dispatch:
release:
types:
- published
- released
types: [published, released]

jobs:
build:
Expand Down
5 changes: 5 additions & 0 deletions changelog/v2.1.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# v2.1.2

* Fixes [superfences bug](https://github.com/neatc0der/mkdocs-markmap/issues/19)
* Updates 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.1'
PROJECT_VERSION = '2.1.2'

OWNER = 'neatc0der'
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'
17 changes: 17 additions & 0 deletions mkdocs_markmap/extension.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from functools import partial
from pathlib import Path
from typing import AnyStr, Dict, List, Optional

Expand Down Expand Up @@ -91,3 +92,19 @@ def __init__(self, **configs: Dict[str, str]):

def extendMarkdown(self, md: Markdown, md_globals: Dict[str, str]) -> None:
md.preprocessors.register(MarkmapPreprocessor(md, self.getConfigs()), 'include_markmap', 102)
for extension in md.registeredExtensions:
if extension.__class__.__name__ == 'SuperFencesCodeExtension':
try:
from pymdownx.superfences import default_validator, fence_code_format, _formatter, _validator
extension.extend_super_fences(
'markmap',
partial(_formatter, class_name='language-markmap', _fmt=fence_code_format),
partial(_validator, validator=default_validator, _legacy=False)
)
break

except ImportError as e:
log.warning(f'detected pymdownx.superfences, but import is not working: {e}')

except Exception as e:
log.error(f'unexpected error: {e}')
20 changes: 15 additions & 5 deletions mkdocs_markmap/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@ 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('code', class_='language-markmap')
markmaps: ResultSet = soup.find_all(class_='language-markmap')
if not any(markmaps):
log.info(f"no markmap found: {page.file.name}")
return output_content

script_base_url: str = re.sub(r'[^/]+?/', '../', re.sub(r'/+?', '/', page.url)) + 'js/'
Expand All @@ -105,11 +106,20 @@ def on_post_page(self, output_content: str, config: Config, **kwargs) -> str:
self._add_statics(soup)

for index, markmap in enumerate(markmaps):
markmap: Tag
tag_id: str = f'markmap-{index}'
markmap.parent.name = 'div'
markmap.parent['class'] = markmap.parent.get('class', []) + ['mkdocs-markmap']
markmap.parent['data-markdown']=markmap.text.replace('\n', '
')
markmap.replaceWith(soup.new_tag(
pre: Tag
code: Tag
if markmap.name == 'pre':
pre = markmap
code = markmap.findChild('code')
else:
pre = markmap.parent
code = markmap
pre.name = 'div'
pre['class'] = pre.get('class', []) + ['mkdocs-markmap']
pre['data-markdown'] = code.text.replace('\n', '
')
code.replaceWith(soup.new_tag(
'svg',
id=tag_id,
attrs={'class': 'markmap'},
Expand Down

0 comments on commit 05c8fe5

Please sign in to comment.