diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-06-10 14:58:09 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-06-10 14:58:09 +0100 |
| commit | 8be57d82ffae15aa753ca57ce19c581bf0d6b897 (patch) | |
| tree | 926707ffc6133094dadae5b46c146ae77ce9be06 | |
| parent | e580cc50fac9440b24854af99f5d0b72594ac0a5 (diff) | |
Add hard-coded footnote reference to HTML
| -rw-r--r-- | lib/document-to-html.js | 8 | ||||
| -rw-r--r-- | lib/documents.js | 10 | ||||
| -rw-r--r-- | tests/document-to-html.tests.js | 8 |
3 files changed, 26 insertions, 0 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 4f38b9d..9741781 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -140,6 +140,14 @@ function DocumentConverter(options) { } }); }, + "footnoteReference": function(element, html, messages, callback) { + html.open(htmlPaths.element("sup")); + html.open(htmlPaths.element("a", {href: "#footnote-" + element.id})); + html.text("1"); + html.close(); + html.close(); + callback(); + }, "image": options.convertImage || defaultConvertImage }; return { diff --git a/lib/documents.js b/lib/documents.js index 061c8c1..12ebc73 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -5,6 +5,7 @@ var types = { text: "text", tab: "tab", hyperlink: "hyperlink", + footnoteReference: "footnoteReference", image: "image" }; @@ -60,6 +61,14 @@ function Hyperlink(children, options) { }; } +function FootnoteReference(options) { + return { + type: types.footnoteReference, + id: options.id, + body: options.body + }; +} + function ElementWithChildren(type) { return function(children, properties) { return { @@ -85,4 +94,5 @@ exports.Run = Run; exports.Text = Text; exports.Tab = Tab; exports.Hyperlink = Hyperlink; +exports.FootnoteReference = FootnoteReference; exports.Image = Image; diff --git a/tests/document-to-html.tests.js b/tests/document-to-html.tests.js index b9a8476..aae8499 100644 --- a/tests/document-to-html.tests.js +++ b/tests/document-to-html.tests.js @@ -197,6 +197,14 @@ describe('DocumentConverter', function() { }); }); + test('footnote reference is converted to superscript intra-page link', function() { + var tab = new documents.FootnoteReference({id: 4, body: paragraphOfText("Hello.")}); + var converter = new DocumentConverter(); + return converter.convertToHtml(tab).then(function(result) { + assert.equal(result.value, '<sup><a href="#footnote-4">1</a></sup>'); + }); + }); + test('images are written with data URIs', function() { var imageBuffer = new Buffer("Not an image at all!"); var image = new documents.Image({ |
