diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-08-30 10:48:30 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-08-30 10:48:30 +0100 |
| commit | 7d5045309a7100dfd2404f0bcdf73d27f4883ab1 (patch) | |
| tree | 0a5e7e94c7670539973f9f29c0133830ef2c3741 | |
| parent | 28d664823a7a1fa58825e6488b9c88c2f6d3cb04 (diff) | |
Add parsing of footnotes XML
| -rw-r--r-- | mammoth/docx/footnotes_xml.py | 21 | ||||
| -rw-r--r-- | tests/docx/footnotes_xml_tests.py | 16 |
2 files changed, 37 insertions, 0 deletions
diff --git a/mammoth/docx/footnotes_xml.py b/mammoth/docx/footnotes_xml.py new file mode 100644 index 0000000..c5ea746 --- /dev/null +++ b/mammoth/docx/footnotes_xml.py @@ -0,0 +1,21 @@ +#~ 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, + element.find_children("w:footnote"), + ) + + +def _read_footnote_element(element): + return FootnoteElement(element.attributes["w:id"], element.children) + + +class FootnoteElement(object): + def __init__(self, id, body): + self.id = id + self.body = body diff --git a/tests/docx/footnotes_xml_tests.py b/tests/docx/footnotes_xml_tests.py new file mode 100644 index 0000000..56caff0 --- /dev/null +++ b/tests/docx/footnotes_xml_tests.py @@ -0,0 +1,16 @@ +from nose.tools import istest, assert_equal, assert_is + +from mammoth.docx.xmlparser import element as xml_element +from mammoth.docx.footnotes_xml import read_footnotes_xml_element + + +@istest +def id_and_body_of_footnote_are_read(): + footnote_body = [xml_element("w:p")] + footnotes = read_footnotes_xml_element(xml_element("w:footnotes", {}, [ + xml_element("w:footnote", {"w:id": "1"}, footnote_body), + ])) + assert_equal(1, len(footnotes)) + assert_is(footnote_body, footnotes[0].body) + assert_equal("1", footnotes[0].id) + |
