|
1 |
| -import sys |
2 |
| - |
| 1 | +import argparse |
3 | 2 | import re
|
4 | 3 | import shutil
|
5 | 4 | import subprocess
|
@@ -68,9 +67,13 @@ def parse_file_toc(file, parent):
|
68 | 67 |
|
69 | 68 | def process_section(elem, parent, module):
|
70 | 69 | 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 |
74 | 77 | if not can_skip_section(section):
|
75 | 78 | process_section(section, child_toc, module)
|
76 | 79 | elif '#' not in href:
|
@@ -109,11 +112,17 @@ def process_resource(dir, output_dir):
|
109 | 112 | style_re = re.compile(r'<link.*?</script>', re.S)
|
110 | 113 |
|
111 | 114 | def process_html(file, output_dir):
|
| 115 | + global args |
112 | 116 | target = output_dir / file.basename()
|
113 |
| - if not target.exists(): |
| 117 | + if not target.exists() or args.force: |
114 | 118 | print('Processing', file)
|
115 | 119 | 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) |
117 | 126 | CHM.append(OUTPUT.relpathto(target))
|
118 | 127 |
|
119 | 128 | def process_module(module):
|
@@ -143,6 +152,10 @@ def main():
|
143 | 152 | process_module(module)
|
144 | 153 |
|
145 | 154 | 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 | + |
146 | 159 | OUTPUT.mkdir_p()
|
147 | 160 | main()
|
148 | 161 | ostyle = OUTPUT / 'style.css'
|
|
0 commit comments