aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-04-08 18:21:11 +0100
committerMichael Williamson <mike@zwobble.org>2015-04-08 18:21:38 +0100
commitb5de440655ace03fb512a67429baf3123126ab0e (patch)
tree28338421ffc90e19d98acfe957439e8a95f92855
parent496a1f7b16fc8616c12f3ebe469c7bfb18a5c00c (diff)
Make style names in style mappings case insensitive
-rw-r--r--NEWS9
-rw-r--r--mammoth/conversion.py2
-rw-r--r--tests/conversion_tests.py13
3 files changed, 23 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index c4cad20..5c424d9 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,12 @@
+# 0.3.12
+
+* Make style names case-insensitive in style mappings. This should make style
+ mappings easier to write, especially since Microsoft Word sometimes represents
+ style names in the UI differently from in the style definition. For instance,
+ the style displayed in Word as "Heading 1" has a style name of "heading 1".
+ This hopefully shouldn't cause an issue for anyone, but if you were relying
+ on case-sensitivity, please do get in touch.
+
# 0.3.11
* Add support for hyperlinks to bookmarks in the same document.
diff --git a/mammoth/conversion.py b/mammoth/conversion.py
index de616ea..e351395 100644
--- a/mammoth/conversion.py
+++ b/mammoth/conversion.py
@@ -227,7 +227,7 @@ def _document_matcher_matches(matcher, element, element_type):
matcher.style_id == element.style_id
) and (
matcher.style_name is None or
- matcher.style_name == element.style_name
+ element.style_name is not None and (matcher.style_name.upper() == element.style_name.upper())
) and (
element_type != "paragraph" or
matcher.numbering is None or
diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py
index 994b1f0..4b5b461 100644
--- a/tests/conversion_tests.py
+++ b/tests/conversion_tests.py
@@ -66,6 +66,19 @@ def style_mappings_using_style_names_can_be_used_to_map_paragraphs():
@istest
+def style_names_in_style_mappings_are_case_insensitive():
+ result = convert_document_element_to_html(
+ documents.paragraph(style_id="TipsParagraph", style_name="Tips Paragraph", children=[
+ _run_with_text("Tip")
+ ]),
+ style_map=[
+ style_reader.read_style("p[style-name='tips paragraph'] => p.tip")
+ ]
+ )
+ assert_equal('<p class="tip">Tip</p>', result.value)
+
+
+@istest
def default_paragraph_style_is_used_if_no_matching_style_is_found():
result = convert_document_element_to_html(
documents.paragraph(style_id="TipsParagraph", children=[