From bf37d9d321dad98f3fa2ca99a5235d07cb66892e Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 7 Jul 2016 21:37:21 +0100 Subject: Wire up comment conversion code --- lib/docx/body-reader.js | 2 +- lib/docx/document-xml-reader.js | 5 ++++- lib/docx/docx-reader.js | 19 +++++++++++++++---- lib/options-reader.js | 2 ++ 4 files changed, 22 insertions(+), 6 deletions(-) (limited to 'lib') 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", -- cgit v1.2.3