From 8fde170b06becb51d2650b60dd28e23eaf862e25 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 5 Nov 2020 19:43:01 +0000 Subject: Add style mapping for all caps --- tests/conversion_tests.py | 19 +++++++++++++++++++ tests/docx/body_xml_tests.py | 1 + tests/styles/parser/document_matcher_parser_tests.py | 9 ++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index 878c804..c4e667f 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -230,6 +230,25 @@ def strikethrough_runs_can_be_configured_with_style_mapping(): assert_equal("Hello", result.value) +@istest +def sml_caps_runs_are_ignored_by_default(): + result = convert_document_element_to_html( + documents.run(children=[documents.text("Hello")], is_all_caps=True), + ) + assert_equal("Hello", result.value) + + +@istest +def all_caps_runs_can_be_mapped_using_style_mapping(): + result = convert_document_element_to_html( + documents.run(children=[documents.text("Hello")], is_all_caps=True), + style_map=[ + _style_mapping("all-caps => span") + ] + ) + assert_equal("Hello", result.value) + + @istest def small_caps_runs_are_ignored_by_default(): result = convert_document_element_to_html( diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 746259c..20f89a9 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -301,6 +301,7 @@ class RunTests(object): param(attr_name="is_underline", tag_name="w:u"), param(attr_name="is_italic", tag_name="w:i"), param(attr_name="is_strikethrough", tag_name="w:strike"), + param(attr_name="is_all_caps", tag_name="w:caps"), param(attr_name="is_small_caps", tag_name="w:smallCaps"), ])(istest(func)) diff --git a/tests/styles/parser/document_matcher_parser_tests.py b/tests/styles/parser/document_matcher_parser_tests.py index dc93941..18233d2 100644 --- a/tests/styles/parser/document_matcher_parser_tests.py +++ b/tests/styles/parser/document_matcher_parser_tests.py @@ -150,6 +150,13 @@ def reads_strikethrough(): read_document_matcher("strike") ) +@istest +def reads_all_caps(): + assert_equal( + document_matchers.all_caps, + read_document_matcher("all-caps") + ) + @istest def reads_small_caps(): assert_equal( @@ -190,7 +197,7 @@ def reads_column_breaks(): def unrecognised_break_type_raises_error(): error = assert_raises(LineParseError, lambda: read_document_matcher("br[type='unknownBreakType']")) assert_equal("Unrecognised break type: unknownBreakType", str(error)) - + def read_document_matcher(string): return parse_document_matcher(TokenIterator(tokenise(string))) -- cgit v1.2.3