Commit 0fa27613 authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Fix for heading containing links

parent fb359f82
Loading
Loading
Loading
Loading
Loading
+8 −2
Changes for generateBaseline/postprocessing.py: 8 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -1139,8 +1139,14 @@ def update_heading_styles(docx_input, docx_output):
    for para in root.xpath('.//w:p[w:pPr/w:pStyle[starts-with(@w:val, "Heading")]]', namespaces=ns):
        if not after_toc(para):
            continue
        # Get all runs in this paragraph
        runs = para.xpath('.//w:r', namespaces=ns)
        # A hyperlink is not a child run. Drop it so para.remove() is only called on w:r children.
        for hyperlink in para.xpath('./w:hyperlink', namespaces=ns):
            link_text = ''.join(hyperlink.xpath('.//w:t/text()', namespaces=ns))
            heading_text = ''.join(para.xpath('./w:r//w:t/text()', namespaces=ns)).strip()
            print(f'WARNING: Removed hyperlink "{link_text}" from heading "{heading_text}"')
            para.remove(hyperlink)
        # Direct child runs only. Nested runs are not children of w:p.
        runs = para.xpath('./w:r', namespaces=ns)
        if not runs:
            continue