summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/body_xml.py12
-rw-r--r--tests/docx/body_xml_tests.py10
2 files changed, 17 insertions, 5 deletions
diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py
index b5e2997..92ac085 100644
--- a/mammoth/docx/body_xml.py
+++ b/mammoth/docx/body_xml.py
@@ -71,7 +71,9 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
def text(element):
return _success(documents.Text(_inner_text(element)))
-
+
+ def element_or_value(element):
+ return element and element.attributes.get("w:val") != "false"
def run(element):
properties = element.find_child_or_null("w:rPr")
@@ -79,10 +81,10 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f
.find_child_or_null("w:vertAlign") \
.attributes.get("w:val")
- is_bold = properties.find_child("w:b")
- is_italic = properties.find_child("w:i")
- is_underline = properties.find_child("w:u")
- is_strikethrough = properties.find_child("w:strike")
+ is_bold = element_or_value(properties.find_child("w:b"))
+ is_italic = element_or_value(properties.find_child("w:i"))
+ is_underline = element_or_value(properties.find_child("w:u"))
+ is_strikethrough = element_or_value(properties.find_child("w:strike"))
return _ReadResult.map_results(
_read_run_style(properties),
diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py
index e1f88d9..b09aba7 100644
--- a/tests/docx/body_xml_tests.py
+++ b/tests/docx/body_xml_tests.py
@@ -174,11 +174,21 @@ class ReadXmlElementTests(object):
def run_is_not_struckthrough_if_strikethrough_element_is_not_present(self):
run = self._read_run_with_properties([])
assert_equal(False, run.is_strikethrough)
+
+ @istest
+ def run_is_not_struckthrough_if_strikethrough_element_is_present_and_false(self):
+ run = self._read_run_with_properties([xml_element("w:strike", {"w:val": "false"})])
+ assert_equal(False, run.is_strikethrough)
@istest
def run_is_struckthrough_if_strikethrough_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:strike")])
assert_equal(True, run.is_strikethrough)
+
+ @istest
+ def run_is_struckthrough_if_strikethrough_element_is_present_and_true(self):
+ run = self._read_run_with_properties([xml_element("w:strike", {"w:val": "true"})])
+ assert_equal(True, run.is_strikethrough)
@istest
def run_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self):