aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-08 21:58:14 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-08 21:58:14 +0100
commit84dcb27be96635789073cc547d6a3b8ee462769e (patch)
tree071f331db5d8017d7a40504653109ba413cb1b72 /mammoth
parent178a640539e1af27fb7b64fc540adc17e58c30c4 (diff)
Add basic style XML reading
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/styles_xml.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/mammoth/docx/styles_xml.py b/mammoth/docx/styles_xml.py
new file mode 100644
index 0000000..548c3e1
--- /dev/null
+++ b/mammoth/docx/styles_xml.py
@@ -0,0 +1,27 @@
+import collections
+
+
+class Styles(object):
+ def __init__(self, paragraph_styles):
+ self._paragraph_styles = paragraph_styles
+
+ def find_paragraph_style_by_id(self, style_id):
+ return self._paragraph_styles.get(style_id)
+
+
+def read_styles_xml_element(element):
+ paragraph_styles = {}
+
+ for style_element in element.find_children("w:style"):
+ style = _read_style_element(style_element)
+ paragraph_styles[style.style_id] = style
+
+ return Styles(paragraph_styles)
+
+
+def _read_style_element(element):
+ style_id = element.attributes["w:styleId"]
+ return Style(style_id=style_id)
+
+
+Style = collections.namedtuple("Style", "style_id")