summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-07-18 15:17:52 +0100
committerMichael Williamson <mike@zwobble.org>2014-07-18 15:17:52 +0100
commit0b4abd3026ac77d8b7ea4f9adde759ca90abc2f6 (patch)
treea159f24d8b178c8106fe2e1b01200966950f1197
parent0bee7e30ca0f184169196e46a85e3a9d9c92eea0 (diff)
Read underlined runs
-rw-r--r--mammoth/documents.py6
-rw-r--r--mammoth/docx/document_xml.py2
-rw-r--r--tests/docx/document_xml_tests.py10
3 files changed, 15 insertions, 3 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 7f2750c..4f67850 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -3,7 +3,7 @@ import dodge
Document = dodge.data_class("Document", ["children"])
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"])
+Run = dodge.data_class("Run", ["children", "style_id", "style_name", "is_bold", "is_italic", "is_underline"])
Text = dodge.data_class("Text", ["value"])
Hyperlink = dodge.data_class("Hyperlink", ["href", "children"])
Table = dodge.data_class("Table", ["children"])
@@ -26,8 +26,8 @@ document = Document
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):
- return Run(children, style_id, style_name, bool(is_bold), bool(is_italic))
+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))
text = Text
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index 75d21fb..32d655c 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -62,6 +62,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file):
is_bold = properties.find_child("w:b")
is_italic = properties.find_child("w:i")
+ is_underline = properties.find_child("w:u")
return _read_xml_elements(element.children) \
.map(lambda children: documents.run(
@@ -70,6 +71,7 @@ def _create_reader(numbering, content_types, relationships, styles, docx_file):
style_name=style_name,
is_bold=is_bold,
is_italic=is_italic,
+ is_underline=is_underline,
))
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index 133726c..984609d 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -131,6 +131,16 @@ class ReadXmlElementTests(object):
def run_is_italic_if_italic_element_is_present(self):
run = self._read_run_with_properties([xml_element("w:i")])
assert_equal(True, run.is_italic)
+
+ @istest
+ def run_is_not_underlined_if_underline_element_is_not_present(self):
+ run = self._read_run_with_properties([])
+ assert_equal(False, run.is_underline)
+
+ @istest
+ def run_is_underlined_if_underline_element_is_present(self):
+ run = self._read_run_with_properties([xml_element("w:u")])
+ assert_equal(True, run.is_underline)
def _read_run_with_properties(self, properties, styles=None):
properties_xml = xml_element("w:rPr", {}, properties)