aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-12-01 13:39:03 +0000
committerMichael Williamson <mike@zwobble.org>2013-12-01 13:39:03 +0000
commit24c6649d0946f2d7bb8157b75caec42b60a2f1e7 (patch)
tree27d0c0913c22be61aa38c34f8dfe4661adae2863
parent71ba0de364add2c5ac0285ae1d8e69cab132baf8 (diff)
Read tab elements
-rw-r--r--mammoth/documents.py5
-rw-r--r--mammoth/docx/document_xml.py6
-rw-r--r--tests/docx/document_xml_tests.py12
3 files changed, 19 insertions, 4 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index d054eef..c8082d3 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -4,6 +4,8 @@ Document = collections.namedtuple("Document", ["children"])
Paragraph = collections.namedtuple("Paragraph", ["children", "style_name", "numbering"])
Run = collections.namedtuple("Run", ["children", "style_name", "is_bold", "is_italic"])
Text = collections.namedtuple("Text", ["value"])
+class Tab(object):
+ pass
document = Document
@@ -15,3 +17,6 @@ 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
+_tab = Tab()
+def tab():
+ return _tab
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index 4bfb8d1..59f9920 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -66,9 +66,13 @@ def _create_reader(numbering):
@handler("w:document")
def document(element):
body_element = _find_child(element, "w:body")
- return documents.Document(_read_xml_elements(body_element.children))
+ return documents.document(_read_xml_elements(body_element.children))
+ @handler("w:tab")
+ def tab(element):
+ return documents.tab()
+
def read(element):
handler = _handlers.get(element.name)
if handler is None:
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index f688e0d..5f64e2b 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -69,7 +69,7 @@ class ReadXmlElementTests(object):
assert_equal("1", paragraph.numbering.level_index)
assert_equal(True, paragraph.numbering.is_ordered)
-
+
@istest
def run_has_no_style_if_it_has_no_properties(self):
element = xml_element("w:r")
@@ -100,12 +100,18 @@ 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)
-
+
def _read_run_with_properties(self, properties):
properties_xml = xml_element("w:rPr", {}, properties)
run_xml = xml_element("w:r", {}, [properties_xml])
return read_document_xml_element(run_xml)
-
+
+
+ @istest
+ def can_read_tab_element(self):
+ element = xml_element("w:tab")
+ tab = read_document_xml_element(element)
+ assert_equal(documents.tab(), tab)
@istest
def unrecognised_elements_are_ignored(self):