aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/body_xml.py1
-rw-r--r--tests/docx/body_xml_tests.py39
2 files changed, 39 insertions, 1 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 091caef..e499cce 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -410,6 +410,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
for cell in row.children
)
if unexpected_non_cells:
+ remove_unmerged_table_cells(rows)
return _elements_result_with_messages(rows, [results.warning(
"unexpected non-cell element in table row, cell merging may be incorrect"
)])
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index 0c86c6e..e9decc4 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -1166,8 +1166,45 @@ class TableTests(object):
def test_warning_if_non_cell_in_table_row(self):
- element = xml_element("w:tbl", {}, [w_tr(xml_element("w:p"))])
+ # Include normal cells to ensure they're still read correctly.
+ element = xml_element("w:tbl", {}, [
+ w_tr(
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Cell 1"),
+ ]),
+ ]),
+ xml_element("w:p"),
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Cell 2"),
+ ]),
+ ]),
+ ),
+ ])
+
result = _read_document_xml_element(element)
+
+ expected_value = documents.table([
+ documents.table_row([
+ documents.table_cell([
+ documents.paragraph([
+ documents.run([
+ documents.text("Cell 1"),
+ ]),
+ ]),
+ ]),
+ documents.paragraph([]),
+ documents.table_cell([
+ documents.paragraph([
+ documents.run([
+ documents.text("Cell 2"),
+ ]),
+ ]),
+ ]),
+ ]),
+ ])
+ assert_equal(expected_value, result.value)
expected_warning = results.warning("unexpected non-cell element in table row, cell merging may be incorrect")
assert_equal([expected_warning], result.messages)