aboutsummaryrefslogtreecommitdiff
path: root/lib/docx
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-01-19 22:48:32 +0000
committerMichael Williamson <mike@zwobble.org>2015-01-19 22:48:32 +0000
commit58cae6030e51481ffb462e52ab6aeb479e0a705d (patch)
tree4e12f82c07c63e03812a4e5d09d0d61a007b3e2d /lib/docx
parent83feedc21e7ba06625837d3c11461d9e8734bf6c (diff)
Operate over a more generic notion of note
Diffstat (limited to 'lib/docx')
-rw-r--r--lib/docx/document-xml-reader.js21
-rw-r--r--lib/docx/docx-reader.js12
-rw-r--r--lib/docx/notes-reader.js1
3 files changed, 22 insertions, 12 deletions
diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js
index 97241a7..c41a29f 100644
--- a/lib/docx/document-xml-reader.js
+++ b/lib/docx/document-xml-reader.js
@@ -13,7 +13,7 @@ function DocumentXmlReader(options) {
var docxFile = options.docxFile;
var numbering = options.numbering;
var styles = options.styles;
- var rawFootnotes = options.footnotes || [];
+ var rawNotes = (options.footnotes || []).concat(options.endnotes || []);
function convertXmlToDocument(documentXml) {
@@ -21,24 +21,25 @@ function DocumentXmlReader(options) {
var result = readXmlElements(body.children)
.flatMap(function(children) {
- return readFootnotes().map(function(footnotes) {
- return new documents.Document(children, {footnotes: footnotes});
+ return readNotes().map(function(notes) {
+ return new documents.Document(children, {notes: notes});
});
});
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,
+ function readNotes() {
+ return Result.combine(rawNotes.map(function(rawNote) {
+ return readXmlElements(rawNote.body).map(function(body) {
+ return new documents.Note({
+ noteType: rawNote.noteType,
+ id: rawNote.id,
body: body
});
});
- })).map(function(footnotes) {
- return new documents.Footnotes(_.indexBy(footnotes, "id"));
+ })).map(function(notes) {
+ return new documents.Notes(notes, "key");
});
}
diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js
index 9326588..23f821c 100644
--- a/lib/docx/docx-reader.js
+++ b/lib/docx/docx-reader.js
@@ -21,15 +21,17 @@ function read(options) {
readNumberingFromZipFile(docxFile),
readStylesFromZipFile(docxFile),
readFootnotesFromZipFile(docxFile),
+ readEndnotesFromZipFile(docxFile),
readXmlFromZipFile(docxFile, "word/document.xml"),
- ]).spread(function(relationships, contentTypes, numbering, styles, footnotes, documentXml) {
+ ]).spread(function(relationships, contentTypes, numbering, styles, footnotes, endnotes, documentXml) {
var reader = new DocumentXmlReader({
relationships: relationships,
contentTypes: contentTypes,
docxFile: docxFile,
numbering: numbering,
styles: styles,
- footnotes: footnotes
+ footnotes: footnotes,
+ endnotes: endnotes
});
return reader.convertXmlToDocument(documentXml);
});
@@ -74,3 +76,9 @@ var readFootnotesFromZipFile = xmlFileReader({
readElement: notesReader.readFootnotesXml,
defaultValue: undefined
});
+
+var readEndnotesFromZipFile = xmlFileReader({
+ filename: "word/endnotes.xml",
+ readElement: notesReader.readEndnotesXml,
+ defaultValue: undefined
+});
diff --git a/lib/docx/notes-reader.js b/lib/docx/notes-reader.js
index 00bcce5..98cbba9 100644
--- a/lib/docx/notes-reader.js
+++ b/lib/docx/notes-reader.js
@@ -1,4 +1,5 @@
exports.readFootnotesXml = createReader("footnote");
+exports.readEndnotesXml = createReader("endnote");
function createReader(noteType) {
function readNotesXml(xml) {