aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-10 15:40:05 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-10 15:40:05 +0100
commit296ac78496e4d94dafd1a4f6f872a1283b796318 (patch)
tree1d30666e971e63a5bf0e4008bf1a0abacde3d0be /lib
parent88b21ba0d0989a5c4f142f5971d33b069a7dfb26 (diff)
Pass all footnotes into document object
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js10
-rw-r--r--lib/documents.js11
-rw-r--r--lib/docx/footnotes-reader.js10
3 files changed, 19 insertions, 12 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index b984089..5b8db9a 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -28,6 +28,8 @@ function DocumentConverter(options) {
function DocumentConversion(options) {
var footnoteNumber = 1;
+ var footnoteIds = [];
+
options = options || {};
var defaultParagraphStyle = htmlPaths.topLevelElement("p");
@@ -73,7 +75,7 @@ function DocumentConversion(options) {
return style.to;
} else {
if (element.styleId) {
- messages.push(unrecognisedStyleWarning("paragraph", element));;
+ messages.push(unrecognisedStyleWarning("paragraph", element));
}
return defaultParagraphStyle;
}
@@ -134,7 +136,10 @@ function DocumentConversion(options) {
} else {
html.closeAll();
html.open(htmlPaths.element("ol"));
- convertElements(document.footnotes, html, messages, function(error) {
+ var footnotes = footnoteIds.map(function(id) {
+ return document.footnotes.findFootnoteById(id);
+ });
+ convertElements(footnotes, html, messages, function(error) {
if (error) {
callback(error);
} else {
@@ -169,6 +174,7 @@ function DocumentConversion(options) {
"footnoteReference": function(element, html, messages, callback) {
html.open(htmlPaths.element("sup"));
html.open(htmlPaths.element("a", {href: "#footnote-" + element.footnoteId}));
+ footnoteIds.push(element.footnoteId);
html.text((footnoteNumber++).toString());
html.close();
html.close();
diff --git a/lib/documents.js b/lib/documents.js
index 135e229..86e0709 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -15,7 +15,7 @@ function Document(children, options) {
return {
type: types.document,
children: children,
- footnotes: options.footnotes || []
+ footnotes: options.footnotes || new Footnotes({})
};
}
@@ -71,6 +71,14 @@ function FootnoteReference(options) {
};
}
+function Footnotes(footnotes) {
+ this._footnotes = footnotes;
+}
+
+Footnotes.prototype.findFootnoteById = function(id) {
+ return this._footnotes[id] || null;
+}
+
function Footnote(options) {
return {
type: types.footnote,
@@ -105,5 +113,6 @@ exports.Text = Text;
exports.Tab = Tab;
exports.Hyperlink = Hyperlink;
exports.FootnoteReference = FootnoteReference;
+exports.Footnotes = Footnotes;
exports.Footnote = Footnote;
exports.Image = Image;
diff --git a/lib/docx/footnotes-reader.js b/lib/docx/footnotes-reader.js
index a55b261..c7ec98c 100644
--- a/lib/docx/footnotes-reader.js
+++ b/lib/docx/footnotes-reader.js
@@ -1,14 +1,6 @@
exports.readFootnotesXml = readFootnotesXml;
-function Footnotes(footnotes) {
- function findFootnoteById(id) {
- return footnotes[id] || null;
- }
-
- return {
- findFootnoteById: findFootnoteById
- };
-}
+var Footnotes = require("../documents").Footnotes;
function readFootnotesXml(xml) {
var footnotes = {};