aboutsummaryrefslogtreecommitdiff
path: root/lib/documents.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-01-19 22:48:32 +0000
committerMichael Williamson <mike@zwobble.org>2015-01-19 22:48:32 +0000
commit58cae6030e51481ffb462e52ab6aeb479e0a705d (patch)
tree4e12f82c07c63e03812a4e5d09d0d61a007b3e2d /lib/documents.js
parent83feedc21e7ba06625837d3c11461d9e8734bf6c (diff)
Operate over a more generic notion of note
Diffstat (limited to 'lib/documents.js')
-rw-r--r--lib/documents.js37
1 files changed, 25 insertions, 12 deletions
diff --git a/lib/documents.js b/lib/documents.js
index b0959cc..aea2b39 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -1,3 +1,5 @@
+var _ = require("underscore");
+
var types = {
document: "document",
paragraph: "paragraph",
@@ -7,7 +9,7 @@ var types = {
hyperlink: "hyperlink",
footnoteReference: "footnoteReference",
image: "image",
- footnote: "footnote",
+ note: "note",
table: "table",
tableRow: "tableRow",
tableCell: "tableCell",
@@ -19,7 +21,7 @@ function Document(children, options) {
return {
type: types.document,
children: children,
- footnotes: options.footnotes || new Footnotes({})
+ notes: options.notes || new Notes({})
};
}
@@ -83,22 +85,33 @@ function FootnoteReference(options) {
};
}
-function Footnotes(footnotes) {
- this._footnotes = footnotes;
+function Notes(notes) {
+ this._notes = _.indexBy(notes, function(note) {
+ return noteKey(note.noteType, note.id);
+ });
}
-Footnotes.prototype.findFootnoteById = function(id) {
- return this._footnotes[id] || null;
+Notes.prototype.findFootnoteById = function(id) {
+ return this.findNoteByKey(noteKey("footnote", id));
+};
+
+Notes.prototype.findNoteByKey = function(key) {
+ return this._notes[key] || null;
};
-function Footnote(options) {
+function Note(options) {
return {
- type: types.footnote,
- body: options.body,
- id: options.id
+ type: types.note,
+ noteType: options.noteType,
+ id: options.id,
+ body: options.body
};
}
+function noteKey(noteType, id) {
+ return noteType + "-" + id;
+}
+
function Image(options) {
return {
type: types.image,
@@ -142,8 +155,8 @@ exports.Text = Text;
exports.Tab = Tab;
exports.Hyperlink = Hyperlink;
exports.FootnoteReference = FootnoteReference;
-exports.Footnotes = Footnotes;
-exports.Footnote = Footnote;
+exports.Notes = Notes;
+exports.Note = Note;
exports.Image = Image;
exports.Table = Table;
exports.TableRow = TableRow;