diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-08-30 11:27:51 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-08-30 11:27:51 +0100 |
| commit | 6ec6e3b4bb8b12ada9609af0bf0e6cd3775fdcef (patch) | |
| tree | 5169420479172025ee3d9f06a99626d1d3bce133 | |
| parent | ce5a4bef9f49f37b934c32da45031d9be4f0f67b (diff) | |
Read footnote references
| -rw-r--r-- | mammoth/documents.py | 2 | ||||
| -rw-r--r-- | mammoth/docx/document_xml.py | 6 | ||||
| -rw-r--r-- | tests/docx/document_xml_tests.py | 6 |
3 files changed, 13 insertions, 1 deletions
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 @@ -316,6 +316,12 @@ class ReadXmlElementTests(object): 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") result = read_document_xml_element(element) |
