Skip to content

Commit fa391a9

Browse files
committed
🐛 Fix(docs/split_readme.py): add function to decrease each md header by one level
1 parent 468c9af commit fa391a9

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

docs/split_readme.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ def convert_gfm_to_sphinx(content, links):
5252
return content
5353

5454

55+
def decrease_header_levels(content):
56+
"""Decrease each Markdown header by one level."""
57+
lines = content.splitlines()
58+
new_lines = []
59+
for line in lines:
60+
if re.match(r"^(#{2,6})\s", line):
61+
num_hashes = len(line.split()[0])
62+
new_line = "#" * (num_hashes - 1) + line[num_hashes:]
63+
new_lines.append(new_line)
64+
else:
65+
new_lines.append(line)
66+
return "\n".join(new_lines)
67+
68+
5569
def process_readme(readme_path, output_dir):
5670
readme = Path(readme_path).read_text()
5771

@@ -67,6 +81,7 @@ def process_readme(readme_path, output_dir):
6781
myst_content = (
6882
f"## {section_title}\n\n{convert_gfm_to_sphinx(content, links)}"
6983
)
84+
myst_content = decrease_header_levels(myst_content)
7085
(output_dir / filename).write_text(myst_content)
7186
print(f"Generated {filename}")
7287
else:

0 commit comments

Comments
 (0)