aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-01 11:33:58 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-01 11:33:58 +0000
commit8d1cc0932083a686e24ff02c9819e507fbb2cb9f (patch)
tree224a71cad9fc8276ef126fbfb2c16ed933190ce9 /mammoth
parentdc381b5afcae0994094d49465142e6099dcec86c (diff)
Read style from paragraph properties
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/mammoth/docx.py b/mammoth/docx.py
index 2f383dd..bf4de0b 100644
--- a/mammoth/docx.py
+++ b/mammoth/docx.py
@@ -47,17 +47,24 @@ def run(element):
@handler("w:p")
def paragraph(element):
- return documents.paragraph(_read_xml_elements(element.children))
+ properties = _find_child(element, "w:pPr")
+ if properties is None:
+ style_name = None
+ else:
+ style_name = _find_child(properties, "w:pStyle").attributes.get("w:val")
+
+ children = _read_xml_elements(element.children)
+ return documents.paragraph(children, style_name)
@handler("w:body")
-def paragraph(element):
+def body(element):
return _read_xml_elements(element.children)
@handler("w:document")
-def paragraph(element):
- body_element = _find(lambda child: child.name == "w:body", element.children)
+def document(element):
+ body_element = _find_child(element, "w:body")
return documents.Document(_read_xml_elements(body_element.children))
@@ -67,6 +74,10 @@ def _find(predicate, iterable):
return item
+def _find_child(element, name):
+ return _find(lambda child: child.name == name, element.children)
+
+
def _read_xml_elements(elements):
return filter(None, map(read_xml_element, elements))