aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-05-12 22:32:49 +0100
committerMichael Williamson <mike@zwobble.org>2016-05-12 22:32:49 +0100
commit220496246ee4648e7d4067bfebd9db44d5e2d151 (patch)
tree135e0eb743cf8a5e0f243003ccbc2ccf60f09e27
parentbd222b2b8cc8d2e95edfbe83a3ef41a2d44be747 (diff)
Write out rowspan when converting to HTML
-rw-r--r--mammoth/conversion.py9
-rw-r--r--tests/conversion_tests.py15
2 files changed, 20 insertions, 4 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index ce4ee21..e05cccc 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -153,10 +153,11 @@ class _DocumentConverter(documents.ElementVisitor):
def visit_table_cell(self, table_cell):
- if table_cell.colspan == 1:
- attributes = {}
- else:
- attributes = {"colspan": str(table_cell.colspan)}
+ attributes = {}
+ if table_cell.colspan != 1:
+ attributes["colspan"] = str(table_cell.colspan)
+ if table_cell.rowspan != 1:
+ attributes["rowspan"] = str(table_cell.rowspan)
nodes = [html.force_write] + self._visit_all(table_cell.children)
return [
html.element("td", attributes, nodes)
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index c989417..287d844 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -348,6 +348,21 @@ def table_cells_are_written_with_colspan_if_not_equal_to_one():
@istest
+def table_cells_are_written_with_rowspan_if_not_equal_to_one():
+ table = documents.table([
+ documents.table_row([
+ documents.table_cell([], rowspan=2),
+ ]),
+ ])
+ result = convert_document_element_to_html(table)
+ expected_html = (
+ "<table>" +
+ "<tr><td rowspan=\"2\"></td></tr>" +
+ "</table>")
+ assert_equal(expected_html, result.value)
+
+
+@istest
def line_break_is_converted_to_br():
line_break = documents.line_break()
result = convert_document_element_to_html(line_break)