aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mammoth/docx/__init__.py6
-rw-r--r--mammoth/docx/document_xml.py6
-rw-r--r--mammoth/docx/notes_xml.py1
-rw-r--r--tests/mammoth_tests.py15
-rw-r--r--tests/test-data/endnotes.docxbin0 -> 4431 bytes
5 files changed, 24 insertions, 4 deletions
diff --git a/mammoth/docx/__init__.py b/mammoth/docx/__init__.py
index 02dad15..8496cd9 100644
--- a/mammoth/docx/__init__.py
+++ b/mammoth/docx/__init__.py
@@ -7,7 +7,7 @@ from .content_types_xml import read_content_types_xml_element
from .relationships_xml import read_relationships_xml_element
from .numbering_xml import read_numbering_xml_element, Numbering
from .styles_xml import read_styles_xml_element
-from .notes_xml import read_footnotes_xml_element
+from .notes_xml import read_footnotes_xml_element, read_endnotes_xml_element
_namespaces = [
@@ -41,6 +41,9 @@ def read(fileobj):
footnote_elements = _try_read_entry_or_default(
zip_file, "word/footnotes.xml", read_footnotes_xml_element, default=[])
+ endnote_elements = _try_read_entry_or_default(
+ zip_file, "word/endnotes.xml", read_endnotes_xml_element, default=[])
+
with _open_entry(zip_file, "word/document.xml") as document_fileobj:
document_xml = _parse_docx_xml(document_fileobj)
return read_document_xml_element(
@@ -51,6 +54,7 @@ def read(fileobj):
numbering=numbering,
styles=styles,
footnote_elements=footnote_elements,
+ endnote_elements=endnote_elements,
)
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py
index ce035ad..c4f0b14 100644
--- a/mammoth/docx/document_xml.py
+++ b/mammoth/docx/document_xml.py
@@ -13,17 +13,17 @@ def read_document_xml_element(element,
relationships=None,
styles=None,
footnote_elements=None,
+ endnote_elements=None,
docx_file=None):
- if footnote_elements is None:
- footnote_elements = []
+ note_elements = (footnote_elements or []) + (endnote_elements or [])
reader = _create_reader(
numbering=numbering,
content_types=content_types,
relationships=relationships,
styles=styles,
- note_elements=footnote_elements,
+ note_elements=note_elements,
docx_file=docx_file,
)
return reader(element)
diff --git a/mammoth/docx/notes_xml.py b/mammoth/docx/notes_xml.py
index c477553..b9b0362 100644
--- a/mammoth/docx/notes_xml.py
+++ b/mammoth/docx/notes_xml.py
@@ -27,3 +27,4 @@ class NoteElement(object):
read_footnotes_xml_element = create_reader("footnote")
+read_endnotes_xml_element = create_reader("endnote")
diff --git a/tests/mammoth_tests.py b/tests/mammoth_tests.py
index 70fac7d..24b2cc9 100644
--- a/tests/mammoth_tests.py
+++ b/tests/mammoth_tests.py
@@ -74,6 +74,21 @@ def footnotes_are_appended_to_text():
@istest
+def endnotes_are_appended_to_text():
+ expected_html = ('<p>Ouch' +
+ '<sup><a href="#endnote-42-2" id="endnote-ref-42-2">[1]</a></sup>.' +
+ '<sup><a href="#endnote-42-3" id="endnote-ref-42-3">[2]</a></sup></p>' +
+ '<ol><li id="endnote-42-2"><p> A tachyon walks into a bar. <a href="#endnote-ref-42-2">↑</a></p></li>' +
+ '<li id="endnote-42-3"><p> Fin. <a href="#endnote-ref-42-3">↑</a></p></li></ol>')
+
+ with open(test_path("endnotes.docx"), "rb") as fileobj:
+ result = mammoth.convert_to_html(fileobj=fileobj, generate_uniquifier=lambda: 42)
+ # TODO: get rid of warnings
+ #~ assert_equal([], result.messages)
+ assert_equal(expected_html, result.value)
+
+
+@istest
def transform_document_is_applied_to_document_before_conversion():
def transform_document(document):
document.children[0].style_id = "Heading1"
diff --git a/tests/test-data/endnotes.docx b/tests/test-data/endnotes.docx
new file mode 100644
index 0000000..1ae4f93
--- /dev/null
+++ b/tests/test-data/endnotes.docx
Binary files differ