From 77303e67f444eae79b5290bb6c3daf6914ba1eb1 Mon Sep 17 00:00:00 2001 From: Shlomi Fish Date: Sat, 24 Aug 2024 13:54:04 +0300 Subject: [PATCH] [WiP] New ToC generator based on querying the docbook XML Get the table-of-contents item depth --- gen-toc-based-on-docbook5.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gen-toc-based-on-docbook5.py b/gen-toc-based-on-docbook5.py index 2bedee9..68f8d42 100644 --- a/gen-toc-based-on-docbook5.py +++ b/gen-toc-based-on-docbook5.py @@ -9,6 +9,8 @@ # import re import unittest +import lxml.etree + import html_unit_test from html_unit_test import ns @@ -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