aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-10 15:22:36 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-10 15:22:36 +0100
commit03293a8e2265dd84eb05a31b8100cf1a310c51bb (patch)
tree4d87de615c8fcd81ebeb88b4e1f29d79568ebce5 /lib
parent8be57d82ffae15aa753ca57ce19c581bf0d6b897 (diff)
Add basic footnote output
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js36
-rw-r--r--lib/documents.js21
2 files changed, 49 insertions, 8 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 9741781..5e50e89 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -117,7 +117,22 @@ function DocumentConverter(options) {
var elementConverters = {
"document": function(document, html, messages, callback) {
- convertElements(document.children, html, messages, callback);
+ convertElements(document.children, html, messages, function(error) {
+ if (error) {
+ callback(error);
+ } else {
+ html.closeAll();
+ html.open(htmlPaths.element("ol"));
+ convertElements(document.footnotes, html, messages, function(error) {
+ if (error) {
+ callback(error);
+ } else {
+ html.close();
+ callback();
+ }
+ });
+ }
+ });
},
"paragraph": convertParagraph,
"run": convertRun,
@@ -141,13 +156,28 @@ function DocumentConverter(options) {
});
},
"footnoteReference": function(element, html, messages, callback) {
+ var number = element.footnoteNumber.toString();
html.open(htmlPaths.element("sup"));
- html.open(htmlPaths.element("a", {href: "#footnote-" + element.id}));
- html.text("1");
+ html.open(htmlPaths.element("a", {href: "#footnote-" + number}));
+ html.text(element.footnoteNumber.toString());
html.close();
html.close();
callback();
},
+ "footnote": function(element, html, messages, callback) {
+ html.open(htmlPaths.element("li", {id: "footnote-" + element.footnoteNumber}));
+ var footnoteHtml = new HtmlGenerator();
+ convertElements(element.body, footnoteHtml, messages, function(err) {
+ if (err) {
+ callback(err);
+ } else {
+ footnoteHtml.closeAll();
+ html.append(footnoteHtml);
+ html.close();
+ callback();
+ }
+ });
+ },
"image": options.convertImage || defaultConvertImage
};
return {
diff --git a/lib/documents.js b/lib/documents.js
index 12ebc73..f293ec3 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -6,13 +6,16 @@ var types = {
tab: "tab",
hyperlink: "hyperlink",
footnoteReference: "footnoteReference",
- image: "image"
+ image: "image",
+ footnote: "footnote"
};
-function Document(children) {
+function Document(children, options) {
+ options = options || {};
return {
type: types.document,
- children: children
+ children: children,
+ footnotes: options.footnotes || []
};
}
@@ -64,11 +67,18 @@ function Hyperlink(children, options) {
function FootnoteReference(options) {
return {
type: types.footnoteReference,
- id: options.id,
- body: options.body
+ footnoteNumber: options.footnoteNumber
};
}
+function Footnote(options) {
+ return {
+ type: types.footnote,
+ body: options.body,
+ footnoteNumber: options.footnoteNumber
+ };
+};
+
function ElementWithChildren(type) {
return function(children, properties) {
return {
@@ -95,4 +105,5 @@ exports.Text = Text;
exports.Tab = Tab;
exports.Hyperlink = Hyperlink;
exports.FootnoteReference = FootnoteReference;
+exports.Footnote = Footnote;
exports.Image = Image;