From 0cf349525bee7ff17e8db3f8d04f6d1e9218d3f2 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 21 Jan 2015 19:41:46 +0000 Subject: Add support for endnotes --- mammoth/docx/__init__.py | 6 +++++- mammoth/docx/document_xml.py | 6 +++--- mammoth/docx/notes_xml.py | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) (limited to 'mammoth') 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") -- cgit v1.2.3