aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/docx/body-reader.js9
-rw-r--r--test/docx/body-reader.tests.js38
2 files changed, 46 insertions, 1 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index 776cd5d..e6a70e2 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -521,6 +521,7 @@ function BodyReader(options) {
return row.type !== documents.types.tableRow;
});
if (unexpectedNonRows) {
+ removeVMergeProperties(rows);
return elementResultWithMessages(rows, [warning(
"unexpected non-row element in table, cell merging may be incorrect"
)]);
@@ -563,6 +564,14 @@ function BodyReader(options) {
return elementResult(rows);
}
+ function removeVMergeProperties(rows) {
+ rows.forEach(function(row) {
+ row.children.forEach(function(cell) {
+ delete cell._vMerge;
+ });
+ });
+ }
+
function readDrawingElement(element) {
var blips = element
.getElementsByTagName("a:graphic")
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index c60ef0d..f6c986f 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -1305,10 +1305,46 @@ test("when row is marked as deleted in row properties then row is ignored", func
});
test("warning if non-row in table", function() {
+ // Include normal rows to ensure they're still read correctly.
var tableXml = new XmlElement("w:tbl", {}, [
- new XmlElement("w:p")
+ xml.element("w:tr", {}, [
+ xml.element("w:tc", {}, [
+ xml.element("w:p", {}, [
+ runOfText("Row 1")
+ ])
+ ])
+ ]),
+ new XmlElement("w:p"),
+ xml.element("w:tr", {}, [
+ xml.element("w:tc", {}, [
+ xml.element("w:p", {}, [
+ runOfText("Row 2")
+ ])
+ ])
+ ])
]);
var result = readXmlElement(tableXml);
+ assert.deepEqual(result.value, new documents.Table([
+ new documents.TableRow([
+ new documents.TableCell([
+ new documents.Paragraph([
+ new documents.Run([
+ new documents.Text("Row 1")
+ ])
+ ])
+ ])
+ ]),
+ new documents.Paragraph([]),
+ new documents.TableRow([
+ new documents.TableCell([
+ new documents.Paragraph([
+ new documents.Run([
+ new documents.Text("Row 2")
+ ])
+ ])
+ ])
+ ])
+ ]));
assert.deepEqual(result.messages, [warning("unexpected non-row element in table, cell merging may be incorrect")]);
});