aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-01 11:26:10 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-01 11:26:10 +0000
commitdc381b5afcae0994094d49465142e6099dcec86c (patch)
tree0624f7068dfb5ec9d6ffac0d94d488e93f842c3d /mammoth
parent68047ef381cb08cf43e5a30ca9dd6e40ccde8cdd (diff)
Add style_name to paragraphs
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/documents.py6
-rw-r--r--mammoth/docx.py2
-rw-r--r--mammoth/xmlparser.py4
3 files changed, 9 insertions, 3 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 50b5e65..58e4f6b 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -1,7 +1,11 @@
import collections
+def paragraph(children, style_name=None):
+ return Paragraph(children, style_name)
+
+
Document = collections.namedtuple("Document", ["children"])
-Paragraph = collections.namedtuple("Paragraph", ["children"])
+Paragraph = collections.namedtuple("Paragraph", ["children", "style_name"])
Run = collections.namedtuple("Run", ["children"])
Text = collections.namedtuple("Text", ["value"])
diff --git a/mammoth/docx.py b/mammoth/docx.py
index 9a3fe36..2f383dd 100644
--- a/mammoth/docx.py
+++ b/mammoth/docx.py
@@ -47,7 +47,7 @@ def run(element):
@handler("w:p")
def paragraph(element):
- return documents.Paragraph(_read_xml_elements(element.children))
+ return documents.paragraph(_read_xml_elements(element.children))
@handler("w:body")
diff --git a/mammoth/xmlparser.py b/mammoth/xmlparser.py
index c645ad4..8b26777 100644
--- a/mammoth/xmlparser.py
+++ b/mammoth/xmlparser.py
@@ -6,7 +6,9 @@ XmlElement = collections.namedtuple("XmlElement", ["name", "attributes", "childr
XmlText = collections.namedtuple("XmlText", ["value"])
-element = XmlElement
+def element(name, attributes=None, children=None):
+ return XmlElement(name, attributes or {}, children or [])
+
text = XmlText