summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-06-11 15:38:04 +0100
committerMichael Williamson <mike@zwobble.org>2014-06-11 15:38:04 +0100
commitf9b2d0c27fa9c3407e24dda32301c4f566af8d26 (patch)
tree9962e2bfe7565b77480b445e4c8103e40d637161
parent230dbf291430de43888c9909ac70051d51c44f6b (diff)
Generate links back to main body
-rw-r--r--lib/document-to-html.js15
-rw-r--r--tests/document-to-html.tests.js6
-rw-r--r--tests/mammoth.tests.js9
3 files changed, 21 insertions, 9 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index d7b6a86..faae02b 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -181,8 +181,13 @@ function DocumentConversion(options) {
});
},
"footnoteReference": function(element, html, messages, callback) {
+ var uid = footnoteUid(element.footnoteId);
+
html.open(htmlPaths.element("sup"));
- html.open(htmlPaths.element("a", {href: "#footnote-" + footnoteUid(element.footnoteId)}));
+ html.open(htmlPaths.element("a", {
+ href: "#footnote-" + uid,
+ id: "footnote-ref-" + uid
+ }));
footnoteIds.push(element.footnoteId);
html.text("[" + (footnoteNumber++) + "]");
html.close();
@@ -190,7 +195,9 @@ function DocumentConversion(options) {
callback();
},
"footnote": function(element, html, messages, callback) {
- html.open(htmlPaths.element("li", {id: "footnote-" + footnoteUid(element.id)}));
+ var uid = footnoteUid(element.id);
+
+ html.open(htmlPaths.element("li", {id: "footnote-" + uid}));
var footnoteHtml = new HtmlGenerator();
convertElements(element.body, footnoteHtml, messages, function(err) {
if (err) {
@@ -198,6 +205,10 @@ function DocumentConversion(options) {
} else {
footnoteHtml.closeAll();
html.append(footnoteHtml);
+ html.text(" ");
+ html.open(htmlPaths.element("a", {href: "#footnote-ref-" + uid}));
+ html.text("↑");
+ html.close();
html.close();
callback();
}
diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js
index 51ee625..cf6fa5b 100644
--- a/tests/document-to-html.tests.js
+++ b/tests/document-to-html.tests.js
@@ -206,7 +206,7 @@ describe('DocumentConverter', function() {
generateUniquifier: function() { return 42; }
});
return converter.convertToHtml(footnoteReference).then(function(result) {
- assert.equal(result.value, '<sup><a href="#footnote-42-4">[1]</a></sup>');
+ assert.equal(result.value, '<sup><a href="#footnote-42-4" id="footnote-ref-42-4">[1]</a></sup>');
});
});
@@ -233,8 +233,8 @@ describe('DocumentConverter', function() {
generateUniquifier: function() { return 42; }
});
return converter.convertToHtml(document).then(function(result) {
- var expectedOutput = '<p>Knock knock<sup><a href="#footnote-42-4">[1]</a></sup></p>' +
- '<ol><li id="footnote-42-4"><p>Who\'s there?</p></li></ol>';
+ var expectedOutput = '<p>Knock knock<sup><a href="#footnote-42-4" id="footnote-ref-42-4">[1]</a></sup></p>' +
+ '<ol><li id="footnote-42-4"><p>Who\'s there?</p> <a href="#footnote-ref-42-4">↑</a></li></ol>';
assert.equal(result.value, expectedOutput);
});
});
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 0b529dd..7b502a4 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -89,16 +89,17 @@ describe('mammoth', function() {
});
test('footnotes are appended to text', function() {
- // TODO: generate links back to main body
// TODO: don't duplicate footnotes with multiple references
var docxPath = path.join(__dirname, "test-data/footnotes.docx");
var options = {
generateUniquifier: function() { return 42; }
};
return mammoth.convertToHtml({path: docxPath}, options).then(function(result) {
- var expectedOutput = '<p>Ouch<sup><a href="#footnote-42-1">[1]</a></sup>.<sup><a href="#footnote-42-2">[2]</a></sup></p>' +
- '<ol><li id="footnote-42-1"><p> A tachyon walks into a bar.</p></li>' +
- '<li id="footnote-42-2"><p> Fin.</p></li></ol>'
+ var expectedOutput = '<p>Ouch' +
+ '<sup><a href="#footnote-42-1" id="footnote-ref-42-1">[1]</a></sup>.' +
+ '<sup><a href="#footnote-42-2" id="footnote-ref-42-2">[2]</a></sup></p>' +
+ '<ol><li id="footnote-42-1"><p> A tachyon walks into a bar.</p> <a href="#footnote-ref-42-1">↑</a></li>' +
+ '<li id="footnote-42-2"><p> Fin.</p> <a href="#footnote-ref-42-2">↑</a></li></ol>'
assert.equal(result.value, expectedOutput);
// TODO: get rid of warnings
//~ assert.deepEqual(result.messages, []);