From 6ec6e3b4bb8b12ada9609af0bf0e6cd3775fdcef Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 30 Aug 2014 11:27:51 +0100 Subject: Read footnote references --- mammoth/documents.py | 2 ++ mammoth/docx/document_xml.py | 6 +++++- tests/docx/document_xml_tests.py | 6 ++++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/mammoth/documents.py b/mammoth/documents.py index ed98aaa..49b2396 100644 --- a/mammoth/documents.py +++ b/mammoth/documents.py @@ -71,3 +71,5 @@ class Footnotes(object): return not (self == other) footnotes = Footnotes + +footnote_reference = FootnoteReference = dodge.data_class("FootnoteReference", ["footnote_id"]) diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py index 68b4bb3..e909a86 100644 --- a/mammoth/docx/document_xml.py +++ b/mammoth/docx/document_xml.py @@ -141,7 +141,7 @@ def _create_reader(numbering, content_types, relationships, styles, footnote_ele def _read_footnote(element): return _read_xml_elements(element.body).map( lambda body: documents.footnote(element.id, body)) - + @handler("w:tab") def tab(element): @@ -221,6 +221,10 @@ def _create_reader(numbering, content_types, relationships, styles, footnote_ele image = documents.image(alt_text=alt_text, content_type=content_type, open=open_image) return results.success(image) + @handler("w:footnoteReference") + def footnote_reference(element): + return results.success(documents.footnote_reference(element.attributes["w:id"])) + 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 b5b1e19..f95419b 100644 --- a/tests/docx/document_xml_tests.py +++ b/tests/docx/document_xml_tests.py @@ -315,6 +315,12 @@ class ReadXmlElementTests(object): assert_equal("4", footnote.id) assert isinstance(footnote.body[0], documents.Paragraph) + @istest + def footnote_reference_has_id_read(self): + footnote_xml = xml_element("w:footnoteReference", {"w:id": "4"}) + footnote = _read_and_get_document_xml_element(footnote_xml) + assert_equal("4", footnote.footnote_id) + @istest def ignored_elements_are_ignored_without_message(self): element = xml_element("w:bookmarkStart") -- cgit v1.2.3