Skip to content

Commit 19be94e

Browse files
committed
Remove empty paragraph after nagivation
1 parent 9978c15 commit 19be94e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

main.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import sys
2-
1+
import argparse
32
import re
43
import shutil
54
import subprocess
@@ -68,9 +67,13 @@ def parse_file_toc(file, parent):
6867

6968
def process_section(elem, parent, module):
7069
for section in elem.findall('section'):
71-
title = section.get('title')
72-
href = module.basename() / section.get('ref')
73-
child_toc = parent.append(title, href)
70+
title = section.get('title').strip()
71+
# title could be empty
72+
if title:
73+
href = module.basename() / section.get('ref')
74+
child_toc = parent.append(title, href)
75+
else:
76+
child_toc = parent
7477
if not can_skip_section(section):
7578
process_section(section, child_toc, module)
7679
elif '#' not in href:
@@ -109,11 +112,17 @@ def process_resource(dir, output_dir):
109112
style_re = re.compile(r'<link.*?</script>', re.S)
110113

111114
def process_html(file, output_dir):
115+
global args
112116
target = output_dir / file.basename()
113-
if not target.exists():
117+
if not target.exists() or args.force:
114118
print('Processing', file)
115119
with open(file, encoding='utf-8') as r, open(target, 'w', encoding='utf-8') as w:
116-
w.write(style_re.sub('<link rel="stylesheet" type="text/css" href="../style.css" />', r.read(), 1))
120+
content = r.read()
121+
# remove stylesheet set via javascript
122+
content = style_re.sub('<link rel="stylesheet" type="text/css" href="../style.css" />', content, 1)
123+
# remove empty paragraph after navigation button
124+
content = content.replace('</p><p/>', '</p>')
125+
w.write(content)
117126
CHM.append(OUTPUT.relpathto(target))
118127

119128
def process_module(module):
@@ -143,6 +152,10 @@ def main():
143152
process_module(module)
144153

145154
if __name__ == '__main__':
155+
parser = argparse.ArgumentParser()
156+
parser.add_argument('-f', '--force', action='store_true', help='Force process HTML')
157+
args = parser.parse_args()
158+
146159
OUTPUT.mkdir_p()
147160
main()
148161
ostyle = OUTPUT / 'style.css'

0 commit comments

Comments
 (0)