6
6
#
7
7
# Distributed under terms of the MIT license.
8
8
9
- # import re
9
+ import re
10
10
11
+ import argparse
12
+ import sys
11
13
import lxml .etree
12
14
13
15
import html_unit_test
@@ -22,7 +24,7 @@ def test_initial_docbook(self):
22
24
id_attr = '{xml}id' .format (xml = ("{" + ns ['xml' ] + "}" ))
23
25
24
26
def _process_sections ():
25
- output_text = ""
27
+ _toc_text = ""
26
28
while len (sections .xpath_results ):
27
29
section = sections .xpath_results .pop (0 )
28
30
id2 = section .get (id_attr )
@@ -31,6 +33,11 @@ def _process_sections():
31
33
title_xpath , namespaces = ns
32
34
)
33
35
docbook5_title = docbook5_title_list [0 ]
36
+ docbook5_title = re .sub ('\\ n' , ' ' , docbook5_title )
37
+ assert '\n ' not in id2
38
+ if id2 == 'what-is-the-channel-for-topictechnology' :
39
+ docbook5_title = \
40
+ "What is the channel for <em>TOPIC</em>/TECHNOLOGY?"
34
41
count_parent_section_elements = 0
35
42
parent = section
36
43
while parent is not None :
@@ -39,17 +46,32 @@ def _process_sections():
39
46
count_parent_section_elements += 1
40
47
parent = parent .getparent ()
41
48
assert count_parent_section_elements > 0
42
- output_text += "{}* [{}](#{})\n " .format (
43
- (" " * (4 * (count_parent_section_elements - 1 ))),
49
+ _toc_text += "{}* [{}](#{})\n " .format (
50
+ (" " * (3 * (count_parent_section_elements - 1 ))),
44
51
docbook5_title , id2 )
45
- print (output_text )
46
- return output_text
52
+ return _toc_text
47
53
48
- _process_sections ()
49
- if 0 :
50
- for section in sections .xpath_results :
51
- print (section .get (id_attr ))
54
+ return _process_sections ()
55
+
56
+
57
+ def main (argv ):
58
+ parser = argparse .ArgumentParser (
59
+ prog = 'PROG' ,
60
+ formatter_class = argparse .ArgumentDefaultsHelpFormatter )
61
+ parser .add_argument ('--output' , type = str , required = True ,
62
+ help = 'output filename' )
63
+ parser .add_argument ('--input' , type = str , required = True ,
64
+ help = 'Input filename' )
65
+ args = parser .parse_args (argv [1 :])
66
+ out_s = ''
67
+ with open (args .input , "rt" ) as fh :
68
+ out_s += fh .read ()
69
+ output_toc = MyTests ().test_initial_docbook ()
70
+ output_text = output_toc + out_s
71
+
72
+ with open (args .output , "wt" ) as ofh :
73
+ ofh .write (output_text )
52
74
53
75
54
76
if __name__ == '__main__' :
55
- MyTests (). test_initial_docbook ( )
77
+ main ( sys . argv )
0 commit comments