Skip to content

Commit 05c8fe5

Browse files
authored
Merge pull request #25 from neatc0der/release/v2.1.2
Release/v2.1.2
2 parents 229b4c5 + 7c3e805 commit 05c8fe5

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

.github/workflows/distribute.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
name: Distribution Workflow
22

33
on:
4+
workflow_dispatch:
45
release:
5-
types:
6-
- published
7-
- released
6+
types: [published, released]
87

98
jobs:
109
build:

changelog/v2.1.2.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# v2.1.2
2+
3+
* Fixes [superfences bug](https://github.com/neatc0der/mkdocs-markmap/issues/19)
4+
* Updates distribute workflow
5+

mkdocs_markmap/__meta__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PACKAGE_NAME = 'mkdocs_markmap'
22
PROJECT_NAME = PACKAGE_NAME.replace('_', '-')
3-
PROJECT_VERSION = '2.1.1'
3+
PROJECT_VERSION = '2.1.2'
44

55
OWNER = 'neatc0der'
66
REPOSITORY_NAME = f'{OWNER}/{PROJECT_NAME}'

mkdocs_markmap/extension.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22
import re
3+
from functools import partial
34
from pathlib import Path
45
from typing import AnyStr, Dict, List, Optional
56

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

9293
def extendMarkdown(self, md: Markdown, md_globals: Dict[str, str]) -> None:
9394
md.preprocessors.register(MarkmapPreprocessor(md, self.getConfigs()), 'include_markmap', 102)
95+
for extension in md.registeredExtensions:
96+
if extension.__class__.__name__ == 'SuperFencesCodeExtension':
97+
try:
98+
from pymdownx.superfences import default_validator, fence_code_format, _formatter, _validator
99+
extension.extend_super_fences(
100+
'markmap',
101+
partial(_formatter, class_name='language-markmap', _fmt=fence_code_format),
102+
partial(_validator, validator=default_validator, _legacy=False)
103+
)
104+
break
105+
106+
except ImportError as e:
107+
log.warning(f'detected pymdownx.superfences, but import is not working: {e}')
108+
109+
except Exception as e:
110+
log.error(f'unexpected error: {e}')

mkdocs_markmap/plugin.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ def on_post_page(self, output_content: str, config: Config, **kwargs) -> str:
9595
soup: BeautifulSoup = BeautifulSoup(output_content, 'html.parser')
9696
page: Page = kwargs.get('page')
9797

98-
markmaps: ResultSet = soup.find_all('code', class_='language-markmap')
98+
markmaps: ResultSet = soup.find_all(class_='language-markmap')
9999
if not any(markmaps):
100+
log.info(f"no markmap found: {page.file.name}")
100101
return output_content
101102

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

107108
for index, markmap in enumerate(markmaps):
109+
markmap: Tag
108110
tag_id: str = f'markmap-{index}'
109-
markmap.parent.name = 'div'
110-
markmap.parent['class'] = markmap.parent.get('class', []) + ['mkdocs-markmap']
111-
markmap.parent['data-markdown']=markmap.text.replace('\n', '
')
112-
markmap.replaceWith(soup.new_tag(
111+
pre: Tag
112+
code: Tag
113+
if markmap.name == 'pre':
114+
pre = markmap
115+
code = markmap.findChild('code')
116+
else:
117+
pre = markmap.parent
118+
code = markmap
119+
pre.name = 'div'
120+
pre['class'] = pre.get('class', []) + ['mkdocs-markmap']
121+
pre['data-markdown'] = code.text.replace('\n', '
')
122+
code.replaceWith(soup.new_tag(
113123
'svg',
114124
id=tag_id,
115125
attrs={'class': 'markmap'},

0 commit comments

Comments
 (0)