diff options
Diffstat (limited to 'mammoth/docx.py')
| -rw-r--r-- | mammoth/docx.py | 19 |
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)) |
