Loading generateBaseline/postprocessing.py +30 −10 Changes for generateBaseline/postprocessing.py: 30 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -1949,18 +1949,37 @@ def update_table_rows(docx_input, docx_output): counter_tal = 0 counter_tar = 0 # Ensure table paragraphs without pPr are treated like Compact paragraphs. for para in root.xpath('.//w:tr//w:p[not(w:pPr)]', namespaces=ns): pPr = OxmlElement('w:pPr') pStyle = OxmlElement('w:pStyle') pStyle.set(f"{{{ns['w']}}}val", "Compact") pPr.append(pStyle) para.insert(0, pPr) # Find all Compact style elements that are within a w:tr (table row) for elem in root.xpath('.//w:tr//w:pStyle[@w:val="Compact"]', namespaces=ns): for pPr in root.xpath('.//w:tr//w:pPr', namespaces=ns): # Check if the w:p/w:pPr element has a pStyle, if not, add it pStyle_elems = pPr.xpath('./w:pStyle', namespaces=ns) if not pStyle_elems: pStyle_elem = etree.Element(f"{{{ns['w']}}}pStyle") pStyle_elem.set(f"{{{ns['w']}}}val", "Compact") pPr.insert(0, pStyle_elem) elif pStyle_elems[0].get(f"{{{ns['w']}}}val") != "Compact": continue else: pStyle_elem = pStyle_elems[0] # Find the parent w:tr element tr = elem tr = pPr while tr is not None and tr.tag != f"{{{ns['w']}}}tr": tr = tr.getparent() if tr is None: continue # Find the paragraph element that contains this pStyle para = elem # Find the paragraph element that contains this pPr para = pPr while para is not None and para.tag != f"{{{ns['w']}}}p": para = para.getparent() Loading @@ -1970,9 +1989,10 @@ def update_table_rows(docx_input, docx_output): # Check if this row has tblHeader with value "on" tbl_header = tr.xpath('./w:trPr/w:tblHeader[@w:val="on"]', namespaces=ns) if tbl_header: # It's a header row, change to TAH elem.set(f"{{{ns['w']}}}val", "TAH") pStyle_elem.set(f"{{{ns['w']}}}val", "TAH") counter_tah += 1 # Remove ALL properties from pPr except pStyle # Header alignment is implicit in TAH style, so explicit jc must be removed Loading Loading @@ -2018,20 +2038,20 @@ def update_table_rows(docx_input, docx_output): jc_elem = para.xpath('./w:pPr/w:jc', namespaces=ns) if not jc_elem: # No jc present, default to TAC elem.set(f"{{{ns['w']}}}val", "TAC") pStyle_elem.set(f"{{{ns['w']}}}val", "TAC") counter_tac += 1 else: # jc exists, check the value jc_val = jc_elem[0].get(f"{{{ns['w']}}}val") if jc_val == "left": elem.set(f"{{{ns['w']}}}val", "TAL") pStyle_elem.set(f"{{{ns['w']}}}val", "TAL") counter_tal += 1 elif jc_val == "right": elem.set(f"{{{ns['w']}}}val", "TAR") pStyle_elem.set(f"{{{ns['w']}}}val", "TAR") counter_tar += 1 else: # center or other, default to TAC elem.set(f"{{{ns['w']}}}val", "TAC") pStyle_elem.set(f"{{{ns['w']}}}val", "TAC") counter_tac += 1 print(f'Changed style "Compact/TableHeading" to "TAH" {counter_tah} times, "Compact/TableRow" to "TAL" {counter_tal} times, to "TAR" {counter_tar} times, to "TAC" {counter_tac} times') Loading Loading @@ -3243,10 +3263,10 @@ def update_format_styles_cli(): ("update_figure_style", update_figure_style), ("update_table_captions", update_table_captions), ("update_abbreviations", update_abbreviations), ("update_lists", update_lists), ("update_table_rows", update_table_rows), ("update_notes", update_notes), ("update_references", update_references), ("update_lists", update_lists), ("repair_invalid_numbering_references", repair_invalid_numbering_references), ("update_body_text_style", update_body_text_style), ("add_no_break_hyphens", add_no_break_hyphens), Loading Loading
generateBaseline/postprocessing.py +30 −10 Changes for generateBaseline/postprocessing.py: 30 added lines, 10 removed lines. Original line number Diff line number Diff line Loading @@ -1949,18 +1949,37 @@ def update_table_rows(docx_input, docx_output): counter_tal = 0 counter_tar = 0 # Ensure table paragraphs without pPr are treated like Compact paragraphs. for para in root.xpath('.//w:tr//w:p[not(w:pPr)]', namespaces=ns): pPr = OxmlElement('w:pPr') pStyle = OxmlElement('w:pStyle') pStyle.set(f"{{{ns['w']}}}val", "Compact") pPr.append(pStyle) para.insert(0, pPr) # Find all Compact style elements that are within a w:tr (table row) for elem in root.xpath('.//w:tr//w:pStyle[@w:val="Compact"]', namespaces=ns): for pPr in root.xpath('.//w:tr//w:pPr', namespaces=ns): # Check if the w:p/w:pPr element has a pStyle, if not, add it pStyle_elems = pPr.xpath('./w:pStyle', namespaces=ns) if not pStyle_elems: pStyle_elem = etree.Element(f"{{{ns['w']}}}pStyle") pStyle_elem.set(f"{{{ns['w']}}}val", "Compact") pPr.insert(0, pStyle_elem) elif pStyle_elems[0].get(f"{{{ns['w']}}}val") != "Compact": continue else: pStyle_elem = pStyle_elems[0] # Find the parent w:tr element tr = elem tr = pPr while tr is not None and tr.tag != f"{{{ns['w']}}}tr": tr = tr.getparent() if tr is None: continue # Find the paragraph element that contains this pStyle para = elem # Find the paragraph element that contains this pPr para = pPr while para is not None and para.tag != f"{{{ns['w']}}}p": para = para.getparent() Loading @@ -1970,9 +1989,10 @@ def update_table_rows(docx_input, docx_output): # Check if this row has tblHeader with value "on" tbl_header = tr.xpath('./w:trPr/w:tblHeader[@w:val="on"]', namespaces=ns) if tbl_header: # It's a header row, change to TAH elem.set(f"{{{ns['w']}}}val", "TAH") pStyle_elem.set(f"{{{ns['w']}}}val", "TAH") counter_tah += 1 # Remove ALL properties from pPr except pStyle # Header alignment is implicit in TAH style, so explicit jc must be removed Loading Loading @@ -2018,20 +2038,20 @@ def update_table_rows(docx_input, docx_output): jc_elem = para.xpath('./w:pPr/w:jc', namespaces=ns) if not jc_elem: # No jc present, default to TAC elem.set(f"{{{ns['w']}}}val", "TAC") pStyle_elem.set(f"{{{ns['w']}}}val", "TAC") counter_tac += 1 else: # jc exists, check the value jc_val = jc_elem[0].get(f"{{{ns['w']}}}val") if jc_val == "left": elem.set(f"{{{ns['w']}}}val", "TAL") pStyle_elem.set(f"{{{ns['w']}}}val", "TAL") counter_tal += 1 elif jc_val == "right": elem.set(f"{{{ns['w']}}}val", "TAR") pStyle_elem.set(f"{{{ns['w']}}}val", "TAR") counter_tar += 1 else: # center or other, default to TAC elem.set(f"{{{ns['w']}}}val", "TAC") pStyle_elem.set(f"{{{ns['w']}}}val", "TAC") counter_tac += 1 print(f'Changed style "Compact/TableHeading" to "TAH" {counter_tah} times, "Compact/TableRow" to "TAL" {counter_tal} times, to "TAR" {counter_tar} times, to "TAC" {counter_tac} times') Loading Loading @@ -3243,10 +3263,10 @@ def update_format_styles_cli(): ("update_figure_style", update_figure_style), ("update_table_captions", update_table_captions), ("update_abbreviations", update_abbreviations), ("update_lists", update_lists), ("update_table_rows", update_table_rows), ("update_notes", update_notes), ("update_references", update_references), ("update_lists", update_lists), ("repair_invalid_numbering_references", repair_invalid_numbering_references), ("update_body_text_style", update_body_text_style), ("add_no_break_hyphens", add_no_break_hyphens), Loading