diff options
| -rw-r--r-- | lib/docx/body-reader.js | 2 | ||||
| -rw-r--r-- | lib/docx/document-xml-reader.js | 5 | ||||
| -rw-r--r-- | lib/docx/docx-reader.js | 19 | ||||
| -rw-r--r-- | lib/options-reader.js | 2 | ||||
| -rw-r--r-- | test/mammoth.tests.js | 19 | ||||
| -rwxr-xr-x | test/test-data/comments.docx | bin | 0 -> 15526 bytes |
6 files changed, 41 insertions, 6 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index b514363..7b3120d 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -379,13 +379,13 @@ var ignoreElements = { "office-word:wrap": true, "v:shadow": true, "v:shapetype": true, + "w:annotationRef": true, "w:bookmarkEnd": true, "w:sectPr": true, "w:proofErr": true, "w:lastRenderedPageBreak": true, "w:commentRangeStart": true, "w:commentRangeEnd": true, - "w:commentReference": true, "w:del": true, "w:footnoteRef": true, "w:endnoteRef": true, diff --git a/lib/docx/document-xml-reader.js b/lib/docx/document-xml-reader.js index 12ca19e..bb912e4 100644 --- a/lib/docx/document-xml-reader.js +++ b/lib/docx/document-xml-reader.js @@ -12,7 +12,10 @@ function DocumentXmlReader(options) { var result = bodyReader.readXmlElements(body.children) .map(function(children) { - return new documents.Document(children, {notes: options.notes}); + return new documents.Document(children, { + notes: options.notes, + comments: options.comments + }); }); return new Result(result.value, result.messages); } diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index 6ad63ab..57830d7 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -14,6 +14,7 @@ var contentTypesReader = require("./content-types-reader"); var numberingXml = require("./numbering-xml"); var stylesReader = require("./styles-reader"); var notesReader = require("./notes-reader"); +var commentsReader = require("./comments-reader"); var Files = require("./files").Files; @@ -40,6 +41,13 @@ function read(docxFile, input) { } else { return new Result([]); } + }), + comments: readXmlFileWithBody("comments", result, function(bodyReader, xml) { + if (xml) { + return commentsReader.createCommentsReader(bodyReader)(xml); + } else { + return new Result([]); + } }) }; }).also(function(result) { @@ -53,11 +61,14 @@ function read(docxFile, input) { }).then(function(result) { return readXmlFileWithBody("document", result, function(bodyReader, xml) { return result.notes.flatMap(function(notes) { - var reader = new DocumentXmlReader({ - bodyReader: bodyReader, - notes: notes + return result.comments.flatMap(function(comments) { + var reader = new DocumentXmlReader({ + bodyReader: bodyReader, + notes: notes, + comments: comments + }); + return reader.convertXmlToDocument(xml); }); - return reader.convertXmlToDocument(xml); }); }); }); diff --git a/lib/options-reader.js b/lib/options-reader.js index 19934d8..3765fd3 100644 --- a/lib/options-reader.js +++ b/lib/options-reader.js @@ -26,6 +26,8 @@ var standardOptions = exports._standardOptions = { "r[style-name='footnote reference'] =>", "p[style-name='endnote text'] => p", "r[style-name='endnote reference'] =>", + "p[style-name='annotation text'] => p", + "r[style-name='annotation reference'] =>", // LibreOffice "p[style-name='Footnote'] => p", diff --git a/test/mammoth.tests.js b/test/mammoth.tests.js index 12bee96..0515b2a 100644 --- a/test/mammoth.tests.js +++ b/test/mammoth.tests.js @@ -269,6 +269,25 @@ describe('mammoth', function() { }); }); + test('when style mapping is defined for comment references then comments are included', function() { + var docxPath = path.join(__dirname, "test-data/comments.docx"); + var options = { + idPrefix: "doc-42-", + styleMap: "comment-reference => sup" + }; + return mammoth.convertToHtml({path: docxPath}, options).then(function(result) { + var expectedOutput = ( + '<p>Ouch' + + '<sup><a href="#doc-42-comment-0" id="doc-42-comment-ref-0">[MW1]</a></sup>.' + + '<sup><a href="#doc-42-comment-2" id="doc-42-comment-ref-2">[MW2]</a></sup></p>' + + '<dl><dt id="doc-42-comment-0">Comment [MW1]</dt><dd><p>A tachyon walks into a bar. <a href="#doc-42-comment-ref-0">↑</a></p></dd>' + + '<dt id="doc-42-comment-2">Comment [MW2]</dt><dd><p>Fin. <a href="#doc-42-comment-ref-2">↑</a></p></dd></dl>' + ); + assert.equal(result.value, expectedOutput); + assert.deepEqual(result.messages, []); + }); + }); + test('textboxes are read', function() { var docxPath = path.join(__dirname, "test-data/text-box.docx"); return mammoth.convertToHtml({path: docxPath}).then(function(result) { diff --git a/test/test-data/comments.docx b/test/test-data/comments.docx Binary files differnew file mode 100755 index 0000000..32cdae1 --- /dev/null +++ b/test/test-data/comments.docx |
