Skip to content

Commit 77303e6

Browse files
committed
[WiP] New ToC generator based on querying the docbook XML
Get the table-of-contents item depth
1 parent 21765b1 commit 77303e6

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

gen-toc-based-on-docbook5.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# import re
1010
import unittest
1111

12+
import lxml.etree
13+
1214
import html_unit_test
1315
from html_unit_test import ns
1416

@@ -30,7 +32,18 @@ def _process_sections():
3032
title_xpath, namespaces=ns
3133
)
3234
docbook5_title = docbook5_title_list[0]
33-
output_text += "* [{}](#{})\n".format(docbook5_title, id2)
35+
count_parent_section_elements = 0
36+
parent = section
37+
while parent is not None:
38+
tag = lxml.etree.QName(parent).localname
39+
print(tag)
40+
if tag == 'section':
41+
count_parent_section_elements += 1
42+
parent = parent.getparent()
43+
assert count_parent_section_elements > 0
44+
output_text += "{}* [{}](#{})\n".format(
45+
(" " * (count_parent_section_elements - 1)),
46+
docbook5_title, id2)
3447
print(output_text)
3548
return output_text
3649

0 commit comments

Comments
 (0)