Commit 9f1d8b23 authored by Jonas Schüppen's avatar Jonas Schüppen
Browse files

Small adjustments due to EX Style

parent 102be86e
Loading
Loading
Loading
Loading
Loading
+9 −9
Changes for generateBaseline/postprocessing.py: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -1933,10 +1933,10 @@ def update_notes(docx_input, docx_output):
        all_children = [child for child in para if child.tag != f"{{{ns['w']}}}pPr"]
        
        # Check if text matches NOTE pattern: NOTE\s*\d*:
        note_pattern = re.compile(r'NOTES?\s*\d*:?\s+')
        note_pattern = re.compile(r'NOTES?\s*\d*:?\s*')
        note_match = note_pattern.search(full_text)
        # Check if text matches EXAMPLE pattern: EXAMPLE\s*\d*:
        example_pattern = re.compile(r'EXAMPLES?\s*\d*:?\s+')
        example_pattern = re.compile(r'EXAMPLES?\s*\d*:?\s*')
        example_match = example_pattern.search(full_text)
        if note_match:
            # Change style to NO
@@ -1986,7 +1986,7 @@ def update_notes(docx_input, docx_output):
            for child in all_children:
                para.append(child)
        elif example_match:
            # Change style to EW
            # Change style to EX
            pStyle_elem.set(f"{{{ns['w']}}}val", example_style)
            counter_ew += 1
            
@@ -2029,10 +2029,10 @@ def update_notes(docx_input, docx_output):
            for child in all_children:
                para.append(child)
        else:
            # Check whether BlockText is preceded by paragraph style "EW".
            # Check whether BlockText is preceded by paragraph style "EX".
            # Rules:
            # - if preceding paragraph style is EW -> change to PL and stop
            # - if preceding paragraph has a style and it is not EW -> stop (no change)
            # - if preceding paragraph style is EX -> change to PL and stop
            # - if preceding paragraph has a style and it is not EX -> stop (no change)
            # - if no pPr or no pStyle -> continue searching backwards
            # - if not a paragraph -> continue searching backwards
            prev_para = para.getprevious()
@@ -2054,10 +2054,10 @@ def update_notes(docx_input, docx_output):
                prev_pStyle_val = prev_pStyle[0].get(f"{{{ns['w']}}}val")
                if prev_pStyle_val == example_style:
                    pStyle_elem.set(f"{{{ns['w']}}}val", "PL")
                    print(f'Changed style "BlockText" to "PL" because it is preceded by a paragraph with style "EW" (line {prev_para.sourceline})')
                    print(f'Changed style "BlockText" to "PL" because it is preceded by a paragraph with style "EX" (line {prev_para.sourceline})')
                break
            
    print(f'Changed style "BlockText/Notes" to "NO" {counter_no} times and "BlockText/Examples" to "EW" {counter_ew} times')
    print(f'Changed style "BlockText/Notes" to "NO" {counter_no} times and "BlockText/Examples" to "EX" {counter_ew} times')

    xml_data = etree.tostring(root, xml_declaration=True, encoding="UTF-8", standalone="yes")
    
@@ -2925,7 +2925,7 @@ def update_equation_style(docx_input, docx_output):
            current_style = pStyle[0].get(f"{{{ns['w']}}}val")

            # Do not overwrite Example/Note Styles
            if current_style in ["EW", "NO", "TAN"]:
            if current_style in ["EX", "EW", "NO", "TAN"]:
                continue

            pStyle[0].set(f"{{{ns['w']}}}val", new_style)