diff options
| -rw-r--r-- | mammoth/conversion.py | 4 | ||||
| -rw-r--r-- | tests/conversion_tests.py | 23 |
2 files changed, 26 insertions, 1 deletions
diff --git a/mammoth/conversion.py b/mammoth/conversion.py index 4a4cf99..624f6cb 100644 --- a/mammoth/conversion.py +++ b/mammoth/conversion.py @@ -53,7 +53,9 @@ class DocumentConverter(object): def _find_html_path_for_paragraph(self, paragraph): for style in self._styles: document_matcher = style.document_matcher - if document_matcher.element_type == "paragraph" and document_matcher.style_name == paragraph.style_name: + if document_matcher.element_type == "paragraph" and ( + document_matcher.style_name is None or + document_matcher.style_name == paragraph.style_name): return style.html_path return html_paths.path([html_paths.element("p")]) diff --git a/tests/conversion_tests.py b/tests/conversion_tests.py index ab90eb0..d05a103 100644 --- a/tests/conversion_tests.py +++ b/tests/conversion_tests.py @@ -33,5 +33,28 @@ def paragraphs_are_converted_by_satisfying_matching_paths(): 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_name="TipsParagraph", children=[ + _run_with_text("Tip") + ]), + ) + assert_equal('<p>Tip</p>', result.value) + + +@istest +def default_paragraph_style_is_specified_by_mapping_plain_paragraphs(): + result = convert_document_element_to_html( + documents.paragraph(style_name="TipsParagraph", children=[ + _run_with_text("Tip") + ]), + styles=[ + style_reader.read_style("p => p.tip") + ] + ) + assert_equal('<p class="tip">Tip</p>', result.value) + + def _run_with_text(text): return documents.run(children=[documents.text(text)]) |
