diff options
| -rw-r--r-- | NEWS | 4 | ||||
| -rw-r--r-- | mammoth/documents.py | 3 | ||||
| -rw-r--r-- | mammoth/docx/body_xml.py | 2 | ||||
| -rw-r--r-- | tests/docx/body_xml_tests.py | 9 |
4 files changed, 18 insertions, 0 deletions
@@ -1,3 +1,7 @@ +# 1.8.0 + +* Support parsing of run highlights. + # 1.7.1 * Switch the precedence of numbering properties in paragraph properties and the diff --git a/mammoth/documents.py b/mammoth/documents.py index 7559d40..b49a602 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -53,6 +53,7 @@ class Run(HasChildren): vertical_alignment = cobble.field() font = cobble.field() font_size = cobble.field() + highlight = cobble.field() @cobble.data class Text(Element): @@ -128,6 +129,7 @@ def run( vertical_alignment=None, font=None, font_size=None, + highlight=None, ): if vertical_alignment is None: vertical_alignment = VerticalAlignment.baseline @@ -144,6 +146,7 @@ def run( vertical_alignment=vertical_alignment, font=font, font_size=font_size, + highlight=highlight, ) class VerticalAlignment(object): diff --git a/mammoth/docx/body_xml.py b/mammoth/docx/body_xml.py index 005ad3d..83cbd90 100644 --- a/mammoth/docx/body_xml.py +++ b/mammoth/docx/body_xml.py @@ -102,6 +102,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f is_strikethrough = read_boolean_element(properties.find_child("w:strike")) is_all_caps = read_boolean_element(properties.find_child("w:caps")) is_small_caps = read_boolean_element(properties.find_child("w:smallCaps")) + highlight = properties.find_child_or_null("w:highlight").attributes.get("w:val") def add_complex_field_hyperlink(children): hyperlink_kwargs = current_hyperlink_kwargs() @@ -126,6 +127,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file, f vertical_alignment=vertical_alignment, font=font, font_size=font_size, + highlight=highlight, )) def _read_run_style(properties): diff --git a/tests/docx/body_xml_tests.py b/tests/docx/body_xml_tests.py index 44a3e34..18cba72 100644 --- a/tests/docx/body_xml_tests.py +++ b/tests/docx/body_xml_tests.py @@ -405,6 +405,15 @@ class RunTests(object): run = self._read_run_with_properties([font_size_xml]) assert_equal(None, run.font_size) + def test_run_has_no_highlight_by_default(self): + run = self._read_run_with_properties([]) + assert_equal(None, run.highlight) + + def test_run_has_highlight_read_from_properties(self): + highlight_xml = xml_element("w:highlight", {"w:val": "yellow"}) + run = self._read_run_with_properties([highlight_xml]) + assert_equal("yellow", run.highlight) + def _read_run_with_properties(self, properties, styles=None): properties_xml = xml_element("w:rPr", {}, properties) run_xml = xml_element("w:r", {}, [properties_xml]) |
