aboutsummaryrefslogtreecommitdiff
path: root/mammoth/documents.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-08-30 11:24:39 +0100
committerMichael Williamson <mike@zwobble.org>2014-08-30 11:24:39 +0100
commitce5a4bef9f49f37b934c32da45031d9be4f0f67b (patch)
tree46b2dfd28d0547ab5bbcd3924d73c21ffc6ce796 /mammoth/documents.py
parent32d35f2fcdd85f65ea38eb16b772de503f8d4107 (diff)
Read footnotes and store in Document
Diffstat (limited to 'mammoth/documents.py')
-rw-r--r--mammoth/documents.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/mammoth/documents.py b/mammoth/documents.py
index 326fbeb..ed98aaa 100644
--- a/mammoth/documents.py
+++ b/mammoth/documents.py
@@ -1,7 +1,7 @@
import dodge
-Document = dodge.data_class("Document", ["children"])
+Document = dodge.data_class("Document", ["children", "footnotes"])
Paragraph = dodge.data_class("Paragraph", ["children", "style_id", "style_name", "numbering"])
Run = dodge.data_class("Run", ["children", "style_id", "style_name", "is_bold", "is_italic", "is_underline"])
Text = dodge.data_class("Text", ["value"])
@@ -22,7 +22,10 @@ class Image(object):
self.open = open
-document = Document
+def document(children, footnotes=None):
+ if footnotes is None:
+ footnotes = Footnotes({})
+ return Document(children, footnotes)
def paragraph(children, style_id=None, style_name=None, numbering=None):
return Paragraph(children, style_id, style_name, numbering)
@@ -49,3 +52,22 @@ def numbering_level(level_index, is_ordered):
return _NumberingLevel(str(level_index), bool(is_ordered))
_NumberingLevel = dodge.data_class("NumberingLevel", ["level_index", "is_ordered"])
+
+
+footnote = Footnote = dodge.data_class("Footnote", ["id", "body"])
+
+
+class Footnotes(object):
+ def __init__(self, footnotes):
+ self._footnotes = footnotes
+
+ def find_footnote_by_id(self, id):
+ return self._footnotes[id]
+
+ def __eq__(self, other):
+ return isinstance(other, Footnotes) and self._footnotes == other._footnotes
+
+ def __ne__(self, other):
+ return not (self == other)
+
+footnotes = Footnotes