From 3bfa77d64e69d20609c8321a067bfa2651a7eabc Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 17 Jun 2015 15:49:04 +0100 Subject: Add support for strikethrough --- tests/conversion_tests.py | 8 ++++++++ tests/docx/document_xml_tests.py | 10 ++++++++++ tests/mammoth_tests.py | 7 +++++++ tests/test-data/strikethrough.docx | Bin 0 -> 12652 bytes 4 files changed, 25 insertions(+) create mode 100755 tests/test-data/strikethrough.docx (limited to 'tests') diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index 19df77f..1563131 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -200,6 +200,14 @@ def style_mapping_for_underline_runs_does_not_close_parent_elements(): ] ) assert_equal("Hello", result.value) + + +@istest +def strikethrough_runs_are_wrapped_in_s_elements_by_default(): + result = convert_document_element_to_html( + documents.run(children=[documents.text("Hello")], is_strikethrough=True), + ) + assert_equal("Hello", result.value) @istest diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py index f0fa5ab..bc6fcfb 100644 --- a/tests/docx/document_xml_tests.py +++ b/tests/docx/document_xml_tests.py @@ -142,6 +142,16 @@ class ReadXmlElementTests(object): def run_is_underlined_if_underline_element_is_present(self): run = self._read_run_with_properties([xml_element("w:u")]) assert_equal(True, run.is_underline) + + @istest + 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_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_has_baseline_vertical_alignment_if_vertical_alignment_element_is_not_present(self): diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py index e7e7e64..84cb6ea 100644 --- a/tests/mammoth_tests.py +++ b/tests/mammoth_tests.py @@ -130,6 +130,13 @@ def underline_can_be_configured_with_style_mapping(): assert_equal('

The Sunset Tree

', result.value) +@istest +def strikethrough_is_converted_to_s_element_by_default(): + with open(test_path("strikethrough.docx"), "rb") as fileobj: + result = mammoth.convert_to_html(fileobj=fileobj) + assert_equal("

Today's Special: Salmon Sold out

", result.value) + + @istest def transform_document_is_applied_to_document_before_conversion(): def transform_document(document): diff --git a/tests/test-data/strikethrough.docx b/tests/test-data/strikethrough.docx new file mode 100755 index 0000000..0d2b713 Binary files /dev/null and b/tests/test-data/strikethrough.docx differ -- cgit v1.2.3