diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-01-25 17:17:34 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-01-25 17:17:34 +0000 |
| commit | 52c4d01e4a0e35738e8c1db35a5a4a7ab981803d (patch) | |
| tree | 0cce833e77942311d25a7c92828d7f5802be14b5 /lib/document-to-html.js | |
| parent | 2de4641bed73f04d0c1ac345e132c1a79fc48f14 (diff) | |
Use prefix to generate IDs
Diffstat (limited to 'lib/document-to-html.js')
| -rw-r--r-- | lib/document-to-html.js | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index eec329f..b012ea9 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -33,10 +33,9 @@ function DocumentConversion(options) { var noteReferences = []; options = options || {}; - var generateUniquifier = options.generateUniquifier || function() { - return Math.floor(Math.random() * 1000000000000000); - }; - var uniquifier = generateUniquifier(); + var idPrefix = options.idPrefix === undefined ? + Math.floor(Math.random() * 1000000000000000) : + options.idPrefix; var defaultParagraphStyle = htmlPaths.topLevelElement("p"); @@ -140,8 +139,12 @@ function DocumentConversion(options) { }); }); - function noteUid(id) { - return uniquifier + "-" + id; + function noteHtmlId(note) { + return idPrefix + "-" + note.noteType + "-" + note.noteId; + } + + function noteRefHtmlId(note) { + return idPrefix + "-" + note.noteType + "-ref-" + note.noteId; } function convertTable(element, html, messages, callback) { @@ -235,12 +238,10 @@ function DocumentConversion(options) { }); }, "noteReference": function(element, html, messages, callback) { - var uid = noteUid(element.noteId); - html.open(htmlPaths.element("sup")); html.open(htmlPaths.element("a", { - href: "#" + element.noteType + "-" + uid, - id: element.noteType + "-ref-" + uid + href: "#" + noteHtmlId(element), + id: noteRefHtmlId(element) })); noteReferences.push(element); html.text("[" + (noteNumber++) + "]"); @@ -249,16 +250,14 @@ function DocumentConversion(options) { callback(); }, "note": function(element, html, messages, callback) { - var uid = noteUid(element.id); - - html.open(htmlPaths.element("li", {id: element.noteType + "-" + uid})); + html.open(htmlPaths.element("li", {id: noteHtmlId(element)})); var footnoteHtml = new HtmlGenerator(); convertElements(element.body, footnoteHtml, messages, function(err) { if (err) { callback(err); } else { footnoteHtml.text(" "); - footnoteHtml.open(htmlPaths.element("a", {href: "#" + element.noteType + "-ref-" + uid})); + footnoteHtml.open(htmlPaths.element("a", {href: "#" + noteRefHtmlId(element)})); footnoteHtml.text("↑"); footnoteHtml.closeAll(); html.append(footnoteHtml); |
