diff options
| author | Michael Williamson <mike@zwobble.org> | 2025-09-09 09:42:05 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2025-09-09 09:42:05 +0100 |
| commit | b3ce26c39f64e580e1e42c28e829421084455043 (patch) | |
| tree | f0e8fe8b48ff0bc40edbf2973c8a3354f976d4aa /mammoth | |
| parent | 0c872345021d25a0895ccdaf32a3ad076406f3c4 (diff) | |
Test reading of table rows when non-rows are present
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/body_xml.py | 12 |
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) |
