Skip to content

Commit 21765b1

Browse files
committed
[WiP] New ToC generator based on querying the docbook XML
1 parent 990fa44 commit 21765b1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

gen-toc-based-on-docbook5.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#! /usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
# vim:fenc=utf-8
4+
#
5+
# Copyright © 2019 Shlomi Fish <[email protected]>
6+
#
7+
# Distributed under terms of the MIT license.
8+
9+
# import re
10+
import unittest
11+
12+
import html_unit_test
13+
from html_unit_test import ns
14+
15+
16+
class MyTests(html_unit_test.TestCase):
17+
def test_initial_docbook(self):
18+
input_fn = './FAQ.docbook5.xml'
19+
doc = self.doc(input_fn, filetype='docbook5')
20+
sections = doc.xpath('//db:section')
21+
id_attr = '{xml}id'.format(xml=("{" + ns['xml'] + "}"))
22+
23+
def _process_sections():
24+
output_text = ""
25+
while len(sections.xpath_results):
26+
section = sections.xpath_results.pop(0)
27+
id2 = section.get(id_attr)
28+
title_xpath = './db:title/text()'
29+
docbook5_title_list = section.xpath(
30+
title_xpath, namespaces=ns
31+
)
32+
docbook5_title = docbook5_title_list[0]
33+
output_text += "* [{}](#{})\n".format(docbook5_title, id2)
34+
print(output_text)
35+
return output_text
36+
37+
_process_sections()
38+
if 0:
39+
for section in sections.xpath_results:
40+
print(section.get(id_attr))
41+
42+
43+
if __name__ == '__main__':
44+
from pycotap import TAPTestRunner
45+
suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
46+
TAPTestRunner().run(suite)

0 commit comments

Comments
 (0)