Skip to content

Commit

Permalink
[WiP] New ToC generator based on querying the docbook XML
Browse files Browse the repository at this point in the history
Get the table-of-contents item depth
  • Loading branch information
shlomif committed Aug 24, 2024
1 parent 21765b1 commit 77303e6
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gen-toc-based-on-docbook5.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# import re
import unittest

import lxml.etree

import html_unit_test
from html_unit_test import ns

Expand All @@ -30,7 +32,18 @@ def _process_sections():
title_xpath, namespaces=ns
)
docbook5_title = docbook5_title_list[0]
output_text += "* [{}](#{})\n".format(docbook5_title, id2)
count_parent_section_elements = 0
parent = section
while parent is not None:
tag = lxml.etree.QName(parent).localname
print(tag)
if tag == 'section':
count_parent_section_elements += 1
parent = parent.getparent()
assert count_parent_section_elements > 0
output_text += "{}* [{}](#{})\n".format(
(" " * (count_parent_section_elements - 1)),
docbook5_title, id2)
print(output_text)
return output_text

Expand Down

0 comments on commit 77303e6

Please sign in to comment.