aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/document_xml.py6
-rw-r--r--mammoth/lists.py20
-rw-r--r--tests/docx/document_xml_tests.py12
3 files changed, 29 insertions, 9 deletions
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index 8e8dda8..71d744c 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -91,6 +91,10 @@ def _create_reader(numbering):
@handler("w:tab")
def tab(element):
return results.success(documents.tab())
+
+ @handler("w:ins")
+ def ins(element):
+ return _read_xml_elements(element.children)
def read(element):
handler = _handlers.get(element.name)
@@ -106,7 +110,7 @@ def _create_reader(numbering):
def _read_xml_elements(elements):
return results.combine(map(read, elements)) \
- .map(lambda values: lists.filter(None, values))
+ .map(lambda values: lists.collect(values))
return read
diff --git a/mammoth/lists.py b/mammoth/lists.py
index 24fa7c4..a1e188e 100644
--- a/mammoth/lists.py
+++ b/mammoth/lists.py
@@ -1,11 +1,15 @@
import sys
-__all__ = ["filter"]
-
-if sys.version_info[0] == 2:
- filter = filter
-else:
- import builtins
- def filter(*args, **kwargs):
- return list(builtins.filter(*args, **kwargs))
+def collect(values):
+ result = []
+ _collect(values, result)
+ return result
+
+
+def _collect(values, result):
+ for value in values:
+ if isinstance(value, list):
+ _collect(value, result)
+ elif value is not None:
+ result.append(value)
diff --git a/tests/docx/document_xml_tests.py b/tests/docx/document_xml_tests.py
index e643efb..69286eb 100644
--- a/tests/docx/document_xml_tests.py
+++ b/tests/docx/document_xml_tests.py
@@ -112,6 +112,18 @@ class ReadXmlElementTests(object):
element = xml_element("w:tab")
tab = _read_and_get_document_xml_element(element)
assert_equal(documents.tab(), tab)
+
+ @istest
+ def children_of_w_ins_are_converted_normally(self):
+ element = xml_element("w:p", {}, [
+ xml_element("w:ins", {}, [
+ xml_element("w:r")
+ ])
+ ])
+ assert_equal(
+ documents.paragraph([documents.run([])]),
+ _read_and_get_document_xml_element(element)
+ )
@istest
def ignored_elements_are_ignored_without_message(self):