File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff 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+
5569def 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 :
You can’t perform that action at this time.
0 commit comments