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
  • Loading branch information
shlomif committed Aug 24, 2024
1 parent 990fa44 commit 21765b1
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions gen-toc-based-on-docbook5.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
#
# Copyright © 2019 Shlomi Fish <[email protected]>
#
# Distributed under terms of the MIT license.

# import re
import unittest

import html_unit_test
from html_unit_test import ns


class MyTests(html_unit_test.TestCase):
def test_initial_docbook(self):
input_fn = './FAQ.docbook5.xml'
doc = self.doc(input_fn, filetype='docbook5')
sections = doc.xpath('//db:section')
id_attr = '{xml}id'.format(xml=("{" + ns['xml'] + "}"))

def _process_sections():
output_text = ""
while len(sections.xpath_results):
section = sections.xpath_results.pop(0)
id2 = section.get(id_attr)
title_xpath = './db:title/text()'
docbook5_title_list = section.xpath(
title_xpath, namespaces=ns
)
docbook5_title = docbook5_title_list[0]
output_text += "* [{}](#{})\n".format(docbook5_title, id2)
print(output_text)
return output_text

_process_sections()
if 0:
for section in sections.xpath_results:
print(section.get(id_attr))


if __name__ == '__main__':
from pycotap import TAPTestRunner
suite = unittest.TestLoader().loadTestsFromTestCase(MyTests)
TAPTestRunner().run(suite)

0 comments on commit 21765b1

Please sign in to comment.