aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-09 09:38:54 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-09 09:38:54 +0100
commit0c872345021d25a0895ccdaf32a3ad076406f3c4 (patch)
treeadd33de16b8b802b8507b65fe47092ed0fd25ed0
parent70e02c723496d32196dd0323258fb2270d38bbed (diff)
Fix conversion of unmerged table cells
-rw-r--r--NEWS2
-rw-r--r--mammoth/documents.py3
-rw-r--r--tests/conversion_tests.py19
3 files changed, 24 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 41a48cb..af6ce0b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,8 @@
* Ignore style definitions using a style ID that has already been used.
+* Fix conversion of unmerged table cells.
+
# 1.10.0
* Add "Heading" and "Body" styles, as found in documents created by Apple Pages,
diff --git a/mammoth/documents.py b/mammoth/documents.py
index e874775..18cc7b3 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -92,6 +92,9 @@ class TableCellUnmerged:
rowspan = cobble.field()
vmerge = cobble.field()
+ def _accept1(self, visitor, arg0):
+ return visitor.visit_table_cell(self, arg0)
+
def copy(self, **kwargs):
return cobble.copy(self, **kwargs)
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index f11a69f..fd32658 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -386,6 +386,25 @@ def test_docx_table_is_converted_to_table_in_html():
assert_equal(expected_html, result.value)
+def test_unmerged_table_cell_is_treated_as_table_cell():
+ table = documents.table([
+ documents.table_row([
+ documents.table_cell_unmerged(
+ [_paragraph_with_text("Cell")],
+ colspan=1,
+ rowspan=1,
+ vmerge=False,
+ ),
+ ]),
+ ])
+ result = convert_document_element_to_html(table)
+ expected_html = (
+ "<table>" +
+ "<tr><td><p>Cell</p></td></tr>" +
+ "</table>")
+ assert_equal(expected_html, result.value)
+
+
def test_table_style_mappings_can_be_used_to_map_tables():
table = documents.table([], style_name="Normal Table")
result = convert_document_element_to_html(