aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-08 22:04:19 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-08 22:04:19 +0100
commit3c525db3fba3e408db289b4714352b9cdde797db (patch)
tree439d4d72ed1f5d80d5c952a3b852dc388e14b878
parentfc4b652532f0611e4cbaaf2b6558a70ff265ef9c (diff)
Read name of style
-rw-r--r--mammoth/docx/styles_xml.py5
-rw-r--r--tests/docx/styles_xml_tests.py12
2 files changed, 15 insertions, 2 deletions
diff --git a/mammoth/docx/styles_xml.py b/mammoth/docx/styles_xml.py
index 22c8899..c220740 100644
--- a/mammoth/docx/styles_xml.py
+++ b/mammoth/docx/styles_xml.py
@@ -31,7 +31,8 @@ def read_styles_xml_element(element):
def _read_style_element(element):
element_type = element.attributes["w:type"]
style_id = element.attributes["w:styleId"]
- return Style(element_type=element_type, style_id=style_id)
+ name = element.find_child("w:name").attributes["w:val"]
+ return Style(element_type=element_type, style_id=style_id, name=name)
-Style = collections.namedtuple("Style", ["element_type", "style_id"])
+Style = collections.namedtuple("Style", ["element_type", "style_id", "name"])
diff --git a/tests/docx/styles_xml_tests.py b/tests/docx/styles_xml_tests.py
index c4f659d..2f04ade 100644
--- a/tests/docx/styles_xml_tests.py
+++ b/tests/docx/styles_xml_tests.py
@@ -46,6 +46,18 @@ def paragraph_and_character_styles_are_distinct():
assert_equal(None, styles.find_paragraph_style_by_id("Heading1Char"))
+@istest
+def styles_include_names():
+ element = xml_element("w:styles", {}, [
+ _paragraph_style_element("Heading1", "Heading 1"),
+ ])
+ styles = read_styles_xml_element(element)
+ assert_equal(
+ "Heading 1",
+ styles.find_paragraph_style_by_id("Heading1").name
+ )
+
+
def _paragraph_style_element(style_id, name):
return _style_element("paragraph", style_id, name)