From b3ce26c39f64e580e1e42c28e829421084455043 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 9 Sep 2025 09:42:05 +0100 Subject: Test reading of table rows when non-rows are present --- mammoth/docx/body_xml.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'mammoth') diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index f99a799..091caef 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -399,6 +399,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f for row in rows ) if unexpected_non_rows: + remove_unmerged_table_cells(rows) return _elements_result_with_messages(rows, [results.warning( "unexpected non-row element in table, cell merging may be incorrect" )]) @@ -438,6 +439,17 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f return _success(rows) + def remove_unmerged_table_cells(rows): + for row in rows: + for cell_index, cell in enumerate(row.children): + if isinstance(cell, documents.TableCellUnmerged): + row.children[cell_index] = documents.table_cell( + children=cell.children, + colspan=cell.colspan, + rowspan=cell.rowspan, + ) + + def read_child_elements(element): return _read_xml_elements(element.children) -- cgit v1.2.3