aboutsummaryrefslogtreecommitdiff
path: root/lib/docx/document-xml-reader.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-10 16:23:15 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-10 16:23:15 +0100
commit8aec6e713d08a532194b50591fa338ecb9a251f9 (patch)
tree00004b0324527dac50add38cdf6ac39cec604227 /lib/docx/document-xml-reader.js
parentee2fc5da880df5f9ea8cdaebc506d130c3009ce3 (diff)
Basic support for footnotes
Diffstat (limited to 'lib/docx/document-xml-reader.js')
-rw-r--r--lib/docx/document-xml-reader.js21
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js
index 348bccf..6bf20dc 100644
--- a/lib/docx/document-xml-reader.js
+++ b/lib/docx/document-xml-reader.js
@@ -14,19 +14,34 @@ function DocumentXmlReader(options) {
var docxFile = options.docxFile;
var numbering = options.numbering;
var styles = options.styles;
- var footnotes = options.footnotes;
+ var rawFootnotes = options.footnotes || [];
function convertXmlToDocument(documentXml) {
var body = documentXml.root.first("w:body");
var result = readXmlElements(body.children)
- .map(function(children) {
- return new documents.Document(children, footnotes);
+ .flatMap(function(children) {
+ return readFootnotes().map(function(footnotes) {
+ return new documents.Document(children, {footnotes: footnotes});
+ });
});
result.document = result.value;
return result;
}
+
+ function readFootnotes() {
+ return Result.combine(rawFootnotes.map(function(rawFootnote) {
+ return readXmlElements(rawFootnote.body).map(function(body) {
+ return new documents.Footnote({
+ id: rawFootnote.id,
+ body: body
+ });
+ });
+ })).map(function(footnotes) {
+ return new documents.Footnotes(_.indexBy(footnotes, "id"));
+ });
+ }
function readXmlElements(elements) {
var results = elements.map(readXmlElement);