Skip to content

Commit 8e7608e

Browse files
committed
feat: add fix_markdown_block hook
1 parent a3f5a37 commit 8e7608e

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

hooks/fix_markdown_block.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import re
2+
3+
from mkdocs import plugins
4+
5+
6+
# https://www.mkdocs.org/dev-guide/plugins/#events
7+
8+
9+
@plugins.event_priority(90)
10+
def on_page_markdown(markdown, page, config, files):
11+
pattern = r"<pre>\s*.*?<\/pre>"
12+
markdown = re.sub(
13+
pattern,
14+
lambda match: re.sub(r"<code>|</code>", "", match.group(0)),
15+
markdown,
16+
flags=re.DOTALL | re.IGNORECASE,
17+
)
18+
return markdown

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ hooks:
8585
- hooks/edit_url.py
8686
- hooks/tags.py
8787
- hooks/committer.py
88+
- hooks/fix_markdown_block.py
8889

8990
markdown_extensions:
9091
- admonition

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ black==24.4.2
22
Requests==2.31.0
33
sortedcontainers==2.4.0
44
urllib3==1.26.18
5-
mkdocs-material==9.5.20
5+
mkdocs-material==9.5.21
66
mkdocs-glightbox==0.3.7
77
jieba==0.42.1
88
beautifulsoup4==4.12.3

0 commit comments

Comments
 (0)