summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS2
-rw-r--r--mammoth/docx/body_xml.py6
-rw-r--r--tests/docx/body_xml_tests.py38
3 files changed, 46 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index 68b497d..ecd209a 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,8 @@
elements, such as table cells. Previously, the wrapping elements would have
been ignored.
+* Ignore deleted table rows.
+
# 1.9.1
* Ignore AlternateContent elements when there is no Fallback element.
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index 5cef312..f99a799 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -351,6 +351,12 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def table_row(element):
properties = element.find_child_or_null("w:trPr")
+
+ # See 17.13.5.12 del (Deleted Table Row) of ECMA-376 4th edition Part 1
+ is_deleted = bool(properties.find_child("w:del"))
+ if is_deleted:
+ return _empty_result
+
is_header = bool(properties.find_child("w:tblHeader"))
return _read_xml_elements(element.children) \
.map(lambda children: documents.table_row(
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index 994583e..fc677be 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -1079,6 +1079,44 @@ class TableTests(object):
assert_equal(expected_result, result)
+ def test_when_row_is_marked_as_deleted_in_row_properties_then_row_is_ignored(self):
+ element = xml_element("w:tbl", {}, [
+ xml_element("w:tr", {}, [
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Row 1"),
+ ]),
+ ]),
+ ]),
+
+ xml_element("w:tr", {}, [
+ xml_element("w:trPr", {}, [
+ xml_element("w:del")
+ ]),
+ xml_element("w:tc", {}, [
+ xml_element("w:p", {}, [
+ _run_element_with_text("Row 2"),
+ ]),
+ ]),
+ ]),
+ ])
+
+ result = _read_and_get_document_xml_element(element)
+
+ expected_result = documents.table([
+ documents.table_row([
+ documents.table_cell([
+ documents.paragraph([
+ documents.run([
+ documents.text("Row 1"),
+ ]),
+ ]),
+ ]),
+ ]),
+ ])
+ assert_equal(expected_result, result)
+
+
def test_warning_if_non_row_in_table(self):
element = xml_element("w:tbl", {}, [xml_element("w:p")])
result = _read_document_xml_element(element)