aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
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")