summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-10 15:30:53 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-10 15:30:53 +0100
commit88b21ba0d0989a5c4f142f5971d33b069a7dfb26 (patch)
tree33fac80be93195dbf3f8efb10bec5c07d563ca18
parent1fb926a39b9b63513a2d226957ee1b11846f18be (diff)
Number footnotes in html conversion
-rw-r--r--lib/document-to-html.js13
-rw-r--r--tests/document-to-html.tests.js4
2 files changed, 14 insertions, 3 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 6387142..b984089 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -17,6 +17,17 @@ if (typeof setImmediate === "undefined") {
function DocumentConverter(options) {
+ return {
+ convertToHtml: function() {
+ var conversion = new DocumentConversion(options);
+ return conversion.convertToHtml.apply(this, arguments);
+ }
+ };
+}
+
+function DocumentConversion(options) {
+ var footnoteNumber = 1;
+
options = options || {};
var defaultParagraphStyle = htmlPaths.topLevelElement("p");
@@ -158,7 +169,7 @@ function DocumentConverter(options) {
"footnoteReference": function(element, html, messages, callback) {
html.open(htmlPaths.element("sup"));
html.open(htmlPaths.element("a", {href: "#footnote-" + element.footnoteId}));
- html.text(element.footnoteId.toString());
+ html.text((footnoteNumber++).toString());
html.close();
html.close();
callback();
diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js
index c80a921..f030a72 100644
--- a/tests/document-to-html.tests.js
+++ b/tests/document-to-html.tests.js
@@ -199,12 +199,12 @@ describe('DocumentConverter', function() {
test('footnote reference is converted to superscript intra-page link', function() {
var footnoteReference = new documents.FootnoteReference({
- footnoteId: 1,
+ footnoteId: 4,
body: paragraphOfText("Who's there?")
});
var converter = new DocumentConverter();
return converter.convertToHtml(footnoteReference).then(function(result) {
- assert.equal(result.value, '<sup><a href="#footnote-1">1</a></sup>');
+ assert.equal(result.value, '<sup><a href="#footnote-4">1</a></sup>');
});
});