aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-07-03 20:11:29 +0100
committerMichael Williamson <mike@zwobble.org>2016-07-03 20:11:29 +0100
commit64b823c26c385dcd57aff3e19ce19af0489199e0 (patch)
tree6fd829a999631b48d5f76e68d71db96a63d09404
parent43560811efc50e9f14789be137913274e87478a0 (diff)
Read comment references
-rw-r--r--lib/documents.js9
-rw-r--r--lib/docx/body-reader.js7
-rw-r--r--test/docx/body-reader.tests.js10
3 files changed, 26 insertions, 0 deletions
diff --git a/lib/documents.js b/lib/documents.js
index cb45c40..d4a28af 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -10,6 +10,7 @@ var types = exports.types = {
noteReference: "noteReference",
image: "image",
note: "note",
+ commentReference: "commentReference",
comment: "comment",
table: "table",
tableRow: "tableRow",
@@ -113,6 +114,13 @@ function Note(options) {
};
}
+function commentReference(options) {
+ return {
+ type: types.commentReference,
+ commentId: options.commentId
+ };
+}
+
function comment(options) {
return {
type: types.comment,
@@ -182,6 +190,7 @@ exports.Hyperlink = Hyperlink;
exports.noteReference = exports.NoteReference = NoteReference;
exports.Notes = Notes;
exports.Note = Note;
+exports.commentReference = commentReference;
exports.comment = comment;
exports.Image = Image;
exports.Table = Table;
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index c338893..b514363 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -92,6 +92,12 @@ function BodyReader(options) {
};
}
+ function readCommentReference(element) {
+ return elementResult(documents.commentReference({
+ commentId: element.attributes["w:id"]
+ }));
+ }
+
function readChildElements(element) {
return readXmlElements(element.children);
}
@@ -162,6 +168,7 @@ function BodyReader(options) {
"w:tc": readTableCell,
"w:footnoteReference": noteReferenceReader("footnote"),
"w:endnoteReference": noteReferenceReader("endnote"),
+ "w:commentReference": readCommentReference,
"w:br": function(element) {
var breakType = element.attributes["w:type"];
if (breakType) {
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index a02edcc..24c2d8d 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -617,6 +617,16 @@ describe("readXmlElement: ", function() {
assert.deepEqual(result.messages, []);
});
+ test("w:commentReference has ID read", function() {
+ var referenceXml = new XmlElement("w:commentReference", {"w:id": "4"});
+ var result = readXmlElement(referenceXml);
+ assert.deepEqual(
+ result.value,
+ documents.commentReference({commentId: "4"})
+ );
+ assert.deepEqual(result.messages, []);
+ });
+
test("emits warning on unrecognised element", function() {
var unrecognisedElement = new XmlElement("w:not-an-element");
var result = readXmlElement(unrecognisedElement);