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

Adding an spacing after last entry in abbreviations clause

parent 676b15d3
Loading
Loading
Loading
Loading
Loading
+30 −14
Changes for generateBaseline/postprocessing.py: 30 added lines, 14 removed lines.
Original line number Diff line number Diff line
@@ -40,6 +40,18 @@ DEFAULT_FORMAT_STYLE_UPDATES = {
    "sanitize_document_xml": True
}

ns = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}

w_p = f"{{{ns['w']}}}p"
w_pPr = f"{{{ns['w']}}}pPr"
w_spacing = f"{{{ns['w']}}}spacing"
w_r = f"{{{ns['w']}}}r"
w_br = f"{{{ns['w']}}}br"
w_tbl = f"{{{ns['w']}}}tbl"
w_val = f"{{{ns['w']}}}val"
w_before = f"{{{ns['w']}}}before"
w_after = f"{{{ns['w']}}}after"


def load_format_style_updates_config(config_path=None):
    """
@@ -923,6 +935,7 @@ def update_heading_styles(docx_input, docx_output):
            # Insert page break before "Scope" Heading1 and "History" Heading1
            if re.match(r'^1\s+Scope\s*', full_text):
                insert_page_break_before_heading(para, full_text)

        # Annex heading: "Annex A: Title" or "Annex A (informative): Title" or "Annex: Title"
        elif (match := re.match(r'^(Annex\s[A-Z](?:\s*\((?:informative|normative|informative or normative|normative or informative)\))?:|Annex:\s*)\s*(.+)$', full_text, re.IGNORECASE)) is not None:
            annex_letter = match.group(1)
@@ -2820,8 +2833,6 @@ def add_break_after_code_blocks_and_tables(docx_input, docx_output):
    'PL'/'EW') and
    after tables to improve separation from following body text in Word.
    """
    ns = {"w": "http://schemas.openxmlformats.org/wordprocessingml/2006/main"}

    with zipfile.ZipFile(docx_input, 'r') as zin:
        xml_data = zin.read("word/document.xml")

@@ -2830,16 +2841,6 @@ def add_break_after_code_blocks_and_tables(docx_input, docx_output):
    if body is None:
        return

    w_p = f"{{{ns['w']}}}p"
    w_pPr = f"{{{ns['w']}}}pPr"
    w_spacing = f"{{{ns['w']}}}spacing"
    w_r = f"{{{ns['w']}}}r"
    w_br = f"{{{ns['w']}}}br"
    w_tbl = f"{{{ns['w']}}}tbl"
    w_val = f"{{{ns['w']}}}val"
    w_before = f"{{{ns['w']}}}before"
    w_after = f"{{{ns['w']}}}after"

    def _paragraph_style_val(elem):
        if elem is None or elem.tag != w_p:
            return None
@@ -2860,6 +2861,7 @@ def add_break_after_code_blocks_and_tables(docx_input, docx_output):

    code_break_paras = 0
    table_break_paras = 0
    abbrev_break_paras = 0
    in_abbreviations_clause = False
    for elem in list(body):
        # Track whether we are currently inside an "Abbreviations" top-level section.
@@ -2868,9 +2870,22 @@ def add_break_after_code_blocks_and_tables(docx_input, docx_output):
            style_val = _paragraph_style_val(elem)
            if style_val == "Heading1":
                heading_text = _normalize_ws(_paragraph_text(elem))
                in_abbreviations_clause = bool(
                is_abbreviations_heading = bool(
                    re.search(r'\babbreviations\b', heading_text, flags=re.IGNORECASE)
                )
                if in_abbreviations_clause and not is_abbreviations_heading:
                    prev = elem.getprevious()
                    if not _is_empty_paragraph(prev):
                        sep_p = etree.Element(w_p)
                        sep_pPr = etree.Element(w_pPr)
                        sep_spacing = etree.Element(w_spacing)
                        sep_spacing.set(w_before, "0")
                        sep_spacing.set(w_after, "0")
                        sep_pPr.append(sep_spacing)
                        sep_p.append(sep_pPr)
                        body.insert(body.index(elem), sep_p)
                        abbrev_break_paras += 1
                in_abbreviations_clause = is_abbreviations_heading

        # After PL/EW paragraphs: insert one empty paragraph with zero spacing.
        style_val = _paragraph_style_val(elem)
@@ -2913,7 +2928,8 @@ def add_break_after_code_blocks_and_tables(docx_input, docx_output):

    print(
        f'Inserted minimal separators: post-code/example paragraphs={code_break_paras}, '
        f'post-table paragraphs={table_break_paras}'
        f'post-table paragraphs={table_break_paras}, '
        f'post-abbreviations paragraphs={abbrev_break_paras}'
    )

    xml_data = etree.tostring(root, xml_declaration=True, encoding="UTF-8", standalone="yes")