aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-01-25 17:17:34 +0000
committerMichael Williamson <mike@zwobble.org>2015-01-25 17:17:34 +0000
commit52c4d01e4a0e35738e8c1db35a5a4a7ab981803d (patch)
tree0cce833e77942311d25a7c92828d7f5802be14b5 /lib
parent2de4641bed73f04d0c1ac345e132c1a79fc48f14 (diff)
Use prefix to generate IDs
Diffstat (limited to 'lib')
-rw-r--r--lib/document-to-html.js27
-rw-r--r--lib/documents.js4
-rw-r--r--lib/docx/document-xml-reader.js2
3 files changed, 16 insertions, 17 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);
diff --git a/lib/documents.js b/lib/documents.js
index 5ec8aaf..78bea1a 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -88,7 +88,7 @@ function NoteReference(options) {
function Notes(notes) {
this._notes = _.indexBy(notes, function(note) {
- return noteKey(note.noteType, note.id);
+ return noteKey(note.noteType, note.noteId);
});
}
@@ -104,7 +104,7 @@ function Note(options) {
return {
type: types.note,
noteType: options.noteType,
- id: options.id,
+ noteId: options.noteId,
body: options.body
};
}
diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js
index 1d14758..12016b0 100644
--- a/lib/docx/document-xml-reader.js
+++ b/lib/docx/document-xml-reader.js
@@ -34,7 +34,7 @@ function DocumentXmlReader(options) {
return readXmlElements(rawNote.body).map(function(body) {
return new documents.Note({
noteType: rawNote.noteType,
- id: rawNote.id,
+ noteId: rawNote.id,
body: body
});
});