summaryrefslogtreecommitdiff
path: root/mammoth/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-09 09:42:05 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-09 09:42:05 +0100
commitb3ce26c39f64e580e1e42c28e829421084455043 (patch)
treef0e8fe8b48ff0bc40edbf2973c8a3354f976d4aa /mammoth/docx
parent0c872345021d25a0895ccdaf32a3ad076406f3c4 (diff)
Test reading of table rows when non-rows are present
Diffstat (limited to 'mammoth/docx')
-rw-r--r--mammoth/docx/body_xml.py12
1 files changed, 12 insertions, 0 deletions
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)