aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/documents.py19
-rw-r--r--mammoth/docx/document_xml.py7
2 files changed, 22 insertions, 4 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 49b2396..e7a46c4 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -3,7 +3,10 @@ import dodge
Document = dodge.data_class("Document", ["children", "footnotes"])
Paragraph = dodge.data_class("Paragraph", ["children", "style_id", "style_name", "numbering"])
-Run = dodge.data_class("Run", ["children", "style_id", "style_name", "is_bold", "is_italic", "is_underline"])
+Run = dodge.data_class("Run", [
+ "children", "style_id", "style_name", "is_bold", "is_italic",
+ "is_underline", "vertical_alignment",
+])
Text = dodge.data_class("Text", ["value"])
Hyperlink = dodge.data_class("Hyperlink", ["href", "children"])
Table = dodge.data_class("Table", ["children"])
@@ -30,8 +33,18 @@ def document(children, footnotes=None):
def paragraph(children, style_id=None, style_name=None, numbering=None):
return Paragraph(children, style_id, style_name, numbering)
-def run(children, style_id=None, style_name=None, is_bold=None, is_italic=None, is_underline=None):
- return Run(children, style_id, style_name, bool(is_bold), bool(is_italic), bool(is_underline))
+def run(children, style_id=None, style_name=None, is_bold=None, is_italic=None, is_underline=None, vertical_alignment=None):
+ if vertical_alignment is None:
+ vertical_alignment = VerticalAlignment.baseline
+ return Run(
+ children, style_id, style_name, bool(is_bold), bool(is_italic),
+ bool(is_underline), vertical_alignment,
+ )
+
+class VerticalAlignment(object):
+ baseline = "baseline"
+ superscript = "superscript"
+ subscript = "subscript"
text = Text
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index e909a86..cdc870a 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -70,7 +70,11 @@ def _create_reader(numbering, content_types, relationships, styles, footnote_ele
style_name = None
else:
style_name = styles.find_character_style_by_id(style_id).name
-
+
+ vertical_alignment = properties \
+ .find_child_or_null("w:vertAlign") \
+ .attributes.get("w:val")
+
is_bold = properties.find_child("w:b")
is_italic = properties.find_child("w:i")
is_underline = properties.find_child("w:u")
@@ -83,6 +87,7 @@ def _create_reader(numbering, content_types, relationships, styles, footnote_ele
is_bold=is_bold,
is_italic=is_italic,
is_underline=is_underline,
+ vertical_alignment=vertical_alignment,
))