aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-01 13:36:13 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-01 13:36:13 +0000
commit71ba0de364add2c5ac0285ae1d8e69cab132baf8 (patch)
tree593a4069882f9dc6913a12bb2ac356d8e4ef7f1f
parentbc62c8382815d5ca3b0812247cbc46ba8430ebab (diff)
Read italic property of 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 03975b2..d054eef 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -2,7 +2,7 @@ import collections
Document = collections.namedtuple("Document", ["children"])
Paragraph = collections.namedtuple("Paragraph", ["children", "style_name", "numbering"])
-Run = collections.namedtuple("Run", ["children", "style_name", "is_bold"])
+Run = collections.namedtuple("Run", ["children", "style_name", "is_bold", "is_italic"])
Text = collections.namedtuple("Text", ["value"])
@@ -11,7 +11,7 @@ document = Document
def paragraph(children, style_name=None, numbering=None):
return Paragraph(children, style_name, numbering)
-def run(children, style_name=None, is_bold=None):
- return Run(children, style_name, bool(is_bold))
+def run(children, style_name=None, is_bold=None, is_italic=None):
+ return Run(children, style_name, bool(is_bold), bool(is_italic))
text = Text
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index 6488a25..4bfb8d1 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -27,11 +27,13 @@ def _create_reader(numbering):
.find_child_or_null("w:rStyle") \
.attributes.get("w:val")
is_bold = properties.find_child("w:b")
+ is_italic = properties.find_child("w:i")
return documents.run(
children=_read_xml_elements(element.children),
style_name=style_name,
is_bold=is_bold,
+ is_italic=is_italic,
)
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index 4722a4c..f688e0d 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -91,6 +91,16 @@ class ReadXmlElementTests(object):
run = self._read_run_with_properties([xml_element("w:b")])
assert_equal(True, run.is_bold)
+ @istest
+ def run_is_not_italic_if_italic_element_is_not_present(self):
+ run = self._read_run_with_properties([])
+ assert_equal(False, run.is_italic)
+
+ @istest
+ 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)
+
def _read_run_with_properties(self, properties):
properties_xml = xml_element("w:rPr", {}, properties)
run_xml = xml_element("w:r", {}, [properties_xml])