summaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-08 22:03:01 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-08 22:03:01 +0100
commitfc4b652532f0611e4cbaaf2b6558a70ff265ef9c (patch)
tree31f5b4cd2f10be120f32dab053353e228b505667 /mammoth
parent84dcb27be96635789073cc547d6a3b8ee462769e (diff)
Distinguish character and paragraph styles
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/styles_xml.py20
1 files changed, 15 insertions, 5 deletions
diff --git a/mammoth/docx/styles_xml.py b/mammoth/docx/styles_xml.py
index 548c3e1..22c8899 100644
--- a/mammoth/docx/styles_xml.py
+++ b/mammoth/docx/styles_xml.py
@@ -2,26 +2,36 @@ import collections
class Styles(object):
- def __init__(self, paragraph_styles):
+ def __init__(self, paragraph_styles, character_styles):
self._paragraph_styles = paragraph_styles
+ self._character_styles = character_styles
def find_paragraph_style_by_id(self, style_id):
return self._paragraph_styles.get(style_id)
+
+ def find_character_style_by_id(self, style_id):
+ return self._character_styles.get(style_id)
def read_styles_xml_element(element):
paragraph_styles = {}
+ character_styles = {}
+ styles = {
+ "paragraph": paragraph_styles,
+ "character": character_styles,
+ }
for style_element in element.find_children("w:style"):
style = _read_style_element(style_element)
- paragraph_styles[style.style_id] = style
+ styles[style.element_type][style.style_id] = style
- return Styles(paragraph_styles)
+ return Styles(paragraph_styles, character_styles)
def _read_style_element(element):
+ element_type = element.attributes["w:type"]
style_id = element.attributes["w:styleId"]
- return Style(style_id=style_id)
+ return Style(element_type=element_type, style_id=style_id)
-Style = collections.namedtuple("Style", "style_id")
+Style = collections.namedtuple("Style", ["element_type", "style_id"])