Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.

Commit 2739da7

Browse files
committed
🔄 synced local 'overrides/' with remote 'overrides/'
1 parent 09a2c09 commit 2739da7

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

overrides/hooks/on_page_markdown.py

+26-23
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,51 @@
11
import re
22

3+
34
def non_breaking_space(markdown):
4-
return re.sub('[\u00A0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]', ' ', markdown)
5+
return re.sub(
6+
"[\u00A0\u1680\u180E\u2000-\u200B\u202F\u205F\u3000\uFEFF]", " ", markdown
7+
)
8+
59

610
def update_heading(markdown):
7-
file_content = markdown.split('\n')
8-
markdown = ''
11+
file_content = markdown.split("\n")
12+
markdown = ""
913
code = False
1014
for line in file_content:
1115
if not code:
12-
if line.startswith('```'):
16+
if line.startswith("```"):
1317
code = True
14-
elif line.startswith('#') and line.count('#')<=5:
15-
heading_number = line.count('#') + 1
16-
line = '#' * heading_number + ' ' + line.replace('#', '')
17-
elif line.startswith('```') and code:
18+
elif line.startswith("#") and line.count("#") <= 5:
19+
heading_number = line.count("#") + 1
20+
line = "#" * heading_number + " " + line.replace("#", "")
21+
elif line.startswith("```") and code:
1822
code = True
19-
markdown += line + '\n'
23+
markdown += line + "\n"
2024
return markdown
2125

26+
2227
def strip_comments(markdown):
23-
file_content = markdown.split('\n')
24-
markdown = ''
25-
for line in file_content:
26-
if not re.search(r'%%(.*)%%', line) or not line.startswith('%%') or not line.endswith('%%'):
27-
markdown += line + '\n'
28-
markdown = re.sub(r'%%(.*)%%', '', markdown, flags=re.DOTALL)
29-
return markdown
28+
return re.sub(r"%%.*?%%", "", markdown, flags=re.DOTALL)
29+
3030

3131
def fix_tags(metadata):
32-
tags = metadata.get('tags', None) or metadata.get('tag', None)
32+
tags = metadata.get("tags", None) or metadata.get("tag", None)
3333
if tags and isinstance(tags, str):
34-
tags = tags.split('/')
34+
tags = tags.split("/")
3535
tags = [tag.strip() for tag in tags]
36-
metadata['tags'] = tags
36+
metadata["tags"] = tags
3737
return metadata
3838

39+
3940
def on_page_markdown(markdown, files, page, config, **kwargs):
40-
config_hooks = config['extra'].get('hooks', {'strip_comments': True, 'fix_heading': False})
41-
if config_hooks['strip_comments']:
41+
config_hooks = config.get(
42+
"extra", {"hooks": {"strip_comments": True, "fix_heading": False}}
43+
).get("hooks", {"strip_comments": True, "fix_heading": False})
44+
if config_hooks.get("strip_comments", True):
4245
markdown = strip_comments(markdown)
43-
if config_hooks['fix_heading']:
46+
if config_hooks.get("fix_heading", False):
4447
markdown = update_heading(markdown)
4548
metadata = fix_tags(page.meta)
4649
page.meta = metadata
4750
markdown = non_breaking_space(markdown)
48-
return markdown
51+
return markdown

0 commit comments

Comments
 (0)