summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/footnotes_xml.py16
-rw-r--r--mammoth/lists.py3
-rw-r--r--tests/docx/footnotes_xml_tests.py18
3 files changed, 30 insertions, 7 deletions
diff --git a/mammoth/docx/footnotes_xml.py b/mammoth/docx/footnotes_xml.py
index c5ea746..1c596ab 100644
--- a/mammoth/docx/footnotes_xml.py
+++ b/mammoth/docx/footnotes_xml.py
@@ -1,15 +1,17 @@
-#~ from .. import documents
-#~ from .. import results
from .. import lists
-#~ from .xmlparser import node_types
-#~
+
def read_footnotes_xml_element(element):
- return lists.map(
- _read_footnote_element,
+ footnote_elements = lists.filter(
+ _is_footnote_element,
element.find_children("w:footnote"),
)
-
+ return lists.map(_read_footnote_element, footnote_elements)
+
+
+def _is_footnote_element(element):
+ return element.attributes.get("w:type") not in ["continuationSeparator", "separator"]
+
def _read_footnote_element(element):
return FootnoteElement(element.attributes["w:id"], element.children)
diff --git a/mammoth/lists.py b/mammoth/lists.py
index 28889a9..cf39b99 100644
--- a/mammoth/lists.py
+++ b/mammoth/lists.py
@@ -17,7 +17,10 @@ def _collect(values, result):
if sys.version_info[0] == 2:
map = map
+ filter = filter
else:
import builtins
def map(*args, **kwargs):
return list(builtins.map(*args, **kwargs))
+ def filter(*args, **kwargs):
+ return list(builtins.filter(*args, **kwargs))
diff --git a/tests/docx/footnotes_xml_tests.py b/tests/docx/footnotes_xml_tests.py
index 56caff0..c3fed04 100644
--- a/tests/docx/footnotes_xml_tests.py
+++ b/tests/docx/footnotes_xml_tests.py
@@ -14,3 +14,21 @@ def id_and_body_of_footnote_are_read():
assert_is(footnote_body, footnotes[0].body)
assert_equal("1", footnotes[0].id)
+
+@istest
+def continuation_separator_is_ignored():
+ _assert_footnote_type_is_ignored("continuationSeparator")
+
+
+@istest
+def separator_is_ignored():
+ _assert_footnote_type_is_ignored("separator")
+
+
+def _assert_footnote_type_is_ignored(footnote_type):
+ footnote_body = [xml_element("w:p")]
+ footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [
+ xml_element("w:footnote", {"w:id": "1", "w:type": footnote_type}, footnote_body),
+ ]))
+ assert_equal(0, len(footnotes))
+