Commit 2ff8198d authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Test heading styles function

parent 2209427f
Loading
Loading
Loading
Loading
Loading
+12 −13
Changes for generateBaseline/postprocessing.py: 12 added lines, 13 removed lines.
Original line number Diff line number Diff line
@@ -903,6 +903,12 @@ def update_heading_styles(docx_input, docx_output):
        # Add the new run to the paragraph
        para.append(new_run)

    def clear_paragraph_content(para):
        # Remove direct children except pPr (covers w:r and wrappers like w:hyperlink)
        for child in list(para):
            if child.tag != f"{{{ns['w']}}}pPr":
                para.remove(child)

    # Read XML
    with zipfile.ZipFile(docx_input, 'r') as zin:
        xml_data = zin.read("word/document.xml")
@@ -913,7 +919,7 @@ def update_heading_styles(docx_input, docx_output):
    h6_counter = 0
    # Find all paragraphs with heading styles (Heading1, Heading2, etc.)
    for para in root.xpath('.//w:p[w:pPr/w:pStyle[starts-with(@w:val, "Heading")]]', namespaces=ns):
        # Get all runs in this paragraph
        # Get all runs in this paragraph (including runs inside hyperlinks)
        runs = para.xpath('.//w:r', namespaces=ns)
        if not runs:
            continue
@@ -931,9 +937,8 @@ def update_heading_styles(docx_input, docx_output):
            number = match.group(1)
            rest_text = match.group(2)
            
            # Clear all existing runs from the paragraph
            for run in runs:
                para.remove(run)
            print(f'Processing heading: {full_text}')
            clear_paragraph_content(para)
            
            # Create new run with number + tab + rest
            create_new_run(para, number, rest_text, "tab")
@@ -947,9 +952,7 @@ def update_heading_styles(docx_input, docx_output):
            annex_letter = match.group(1)
            annex_title = match.group(2)
            
            # Clear all existing runs from the paragraph
            for run in runs:
                para.remove(run)
            clear_paragraph_content(para)
            
            # Create new run with number + break + rest
            create_new_run(para, annex_letter, annex_title, "break")
@@ -967,9 +970,7 @@ def update_heading_styles(docx_input, docx_output):
            annex_letter = match.group(1)
            annex_title = match.group(2)
            
            # Clear all existing runs from the paragraph
            for run in runs:
                para.remove(run)
            clear_paragraph_content(para)
            
            # Create new run with number + break + rest
            create_new_run(para, annex_letter, annex_title, "tab")
@@ -983,9 +984,7 @@ def update_heading_styles(docx_input, docx_output):
            annex_letter = match.group(1)
            annex_title = match.group(2)
            
            # Clear all existing runs from the paragraph
            for run in runs:
                para.remove(run)
            clear_paragraph_content(para)
            
            # Create new run with number + break + rest
            create_new_run(para, annex_letter, annex_title, "tab")