From 0c872345021d25a0895ccdaf32a3ad076406f3c4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 9 Sep 2025 09:38:54 +0100 Subject: Fix conversion of unmerged table cells --- NEWS | 2 ++ mammoth/documents.py | 3 +++ tests/conversion_tests.py | 19 +++++++++++++++++++ 3 files changed, 24 insertions(+) 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 = ( + "" + + "" + + "

Cell

") + 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( -- cgit v1.2.3