aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-05-20 18:17:53 +0100
committerMichael Williamson <mike@zwobble.org>2023-05-20 18:17:53 +0100
commit712e328c04ee6e23590ebd753723c2cb7e40f750 (patch)
tree749f7d62a04ee7bfc788268532f7fb694cf95e8b /lib
parent0894561a06782812a4e73725ede6642da4501db0 (diff)
Support merged paragraphs when revisions are tracked
Diffstat (limited to 'lib')
-rw-r--r--lib/documents.js2
-rw-r--r--lib/docx/body-reader.js43
2 files changed, 35 insertions, 10 deletions
diff --git a/lib/documents.js b/lib/documents.js
index edc9b7c..d29ad1b 100644
--- a/lib/documents.js
+++ b/lib/documents.js
@@ -203,7 +203,7 @@ function BookmarkStart(options) {
exports.document = exports.Document = Document;
exports.paragraph = exports.Paragraph = Paragraph;
exports.run = exports.Run = Run;
-exports.Text = Text;
+exports.text = exports.Text = Text;
exports.tab = exports.Tab = Tab;
exports.Hyperlink = Hyperlink;
exports.noteReference = exports.NoteReference = NoteReference;
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index 61b198b..ca55bb7 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -23,6 +23,12 @@ function createBodyReader(options) {
function BodyReader(options) {
var complexFieldStack = [];
var currentInstrText = [];
+
+ // When a paragraph is marked as deleted, its contents should be combined
+ // with the following paragraph. See 17.13.5.15 del (Deleted Paragraph) of
+ // ECMA-376 4th edition Part 1.
+ var deletedParagraphContents = [];
+
var relationships = options.relationships;
var contentTypes = options.contentTypes;
var docxFile = options.docxFile;
@@ -213,15 +219,34 @@ function BodyReader(options) {
var xmlElementReaders = {
"w:p": function(element) {
- return readXmlElements(element.children)
- .map(function(children) {
- var properties = _.find(children, isParagraphProperties);
- return new documents.Paragraph(
- children.filter(negate(isParagraphProperties)),
- properties
- );
- })
- .insertExtra();
+ var isDeleted = !!element
+ .firstOrEmpty("w:pPr")
+ .firstOrEmpty("w:rPr")
+ .first("w:del");
+
+ if (isDeleted) {
+ element.children.filter(function(child) {
+ return child.name !== "w:pPr";
+ }).forEach(function(child) {
+ deletedParagraphContents.push(child);
+ });
+ return emptyResult();
+ } else {
+ var childrenXml = element.children;
+ if (deletedParagraphContents.length > 0) {
+ childrenXml = deletedParagraphContents.concat(childrenXml);
+ deletedParagraphContents = [];
+ }
+ return readXmlElements(childrenXml)
+ .map(function(children) {
+ var properties = _.find(children, isParagraphProperties);
+ return new documents.Paragraph(
+ children.filter(negate(isParagraphProperties)),
+ properties
+ );
+ })
+ .insertExtra();
+ }
},
"w:pPr": function(element) {
return readParagraphStyle(element).map(function(style) {