aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/document_xml.py6
-rw-r--r--tests/docx/document_xml_tests.py8
2 files changed, 13 insertions, 1 deletions
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index 403f880..c3fb1b7 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -22,7 +22,11 @@ def _create_reader(numbering):
@handler("w:r")
def run(element):
- return documents.run(_read_xml_elements(element.children))
+ properties = element.find_child_or_null("w:rPr")
+ style_name = properties \
+ .find_child_or_null("w:rStyle") \
+ .attributes.get("w:val")
+ return documents.run(_read_xml_elements(element.children), style_name)
@handler("w:p")
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index 6539c54..d2ec1ee 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -75,6 +75,14 @@ class ReadXmlElementTests(object):
element = xml_element("w:r")
assert_equal(None, read_document_xml_element(element).style_name)
+ @istest
+ def run_has_style_name_read_from_run_properties_if_present(self):
+ style_xml = xml_element("w:rStyle", {"w:val": "Emphasis"})
+ properties_xml = xml_element("w:rPr", {}, [style_xml])
+ run_xml = xml_element("w:r", {}, [properties_xml])
+ run = read_document_xml_element(run_xml)
+ assert_equal("Emphasis", run.style_name)
+
@istest
def unrecognised_elements_are_ignored(self):