From b4e617af3d447f7addd2901d9abaaceb1f9b1d9a Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 11 Jun 2014 14:48:39 +0100 Subject: Add uniquifier to footnote IDs --- lib/document-to-html.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/document-to-html.js b/lib/document-to-html.js index bec48b0..d7b6a86 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -31,6 +31,11 @@ function DocumentConversion(options) { var footnoteIds = []; options = options || {}; + var generateUniquifier = options.generateUniquifier || function() { + return Math.floor(Math.random() * 1000000000000000); + }; + var uniquifier = generateUniquifier(); + var defaultParagraphStyle = htmlPaths.topLevelElement("p"); var styleMap = options.styleMap || []; @@ -128,6 +133,10 @@ function DocumentConversion(options) { }).fail(callback); } + function footnoteUid(id) { + return uniquifier + "-" + id; + } + var elementConverters = { "document": function(document, html, messages, callback) { convertElements(document.children, html, messages, function(error) { @@ -173,7 +182,7 @@ function DocumentConversion(options) { }, "footnoteReference": function(element, html, messages, callback) { html.open(htmlPaths.element("sup")); - html.open(htmlPaths.element("a", {href: "#footnote-" + element.footnoteId})); + html.open(htmlPaths.element("a", {href: "#footnote-" + footnoteUid(element.footnoteId)})); footnoteIds.push(element.footnoteId); html.text("[" + (footnoteNumber++) + "]"); html.close(); @@ -181,7 +190,7 @@ function DocumentConversion(options) { callback(); }, "footnote": function(element, html, messages, callback) { - html.open(htmlPaths.element("li", {id: "footnote-" + element.id})); + html.open(htmlPaths.element("li", {id: "footnote-" + footnoteUid(element.id)})); var footnoteHtml = new HtmlGenerator(); convertElements(element.body, footnoteHtml, messages, function(err) { if (err) { -- cgit v1.2.3