diff --git a/doc/post-processor b/doc/post-processor index 5258cda69..8ac9825fb 100755 --- a/doc/post-processor +++ b/doc/post-processor @@ -31,7 +31,7 @@ def parse_arguments(): subparser = subparsers.add_parser('fix-wiki-urls', help='Fix wrongly formatted wiki urls') - subparser.add_argument('filename', help='Name of the XML file') + subparser.add_argument('filename', help='Name of the Docbook file') subparsers.required = True return parser.parse_args() @@ -52,27 +52,36 @@ def subcommand_fix_wiki_urls(arguments): def subcommand_remove_footer(arguments): + """Remove the footer template from the given wiki page.""" filename = arguments.filename tree = etree.parse(filename) root = tree.getroot() - informaltables = [] - def recurse(elem): - for child in elem: - if child.tag == 'informaltable': - informaltables.append((elem, child)) - else: - recurse(child) + # The footer will always be in the last
+ def find_last_section(elem): + if elem.getchildren(): + last_element = elem[-1] + if last_element.tag == 'section': + return find_last_section(last_element) + return elem - recurse(root) + last_section = find_last_section(root) - if informaltables: - parent, child = informaltables[-1] - parent.remove(child) + if last_section.getchildren(): + # Remove all elements till is reached + while last_section[-1].tag != 'informaltable': + last_section.remove(last_section[-1]) + # remove itself + last_section.remove(last_section[-1]) + + # Remove the line "Back to Features introduction or manual pages." + if last_section[-1].text.startswith('Back to'): + last_section.remove(last_section[-1]) processed_xml = etree.tostring(root, encoding='utf-8').decode() with open(filename, 'r') as xml_file: + # and elements which etree skips header = xml_file.readlines()[:2] with open(filename, 'w') as xml_file: