summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-09 09:19:21 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-09 09:19:21 +0100
commit8ca702caace290b532b8e83b44900ff24aca17ff (patch)
treee183552e1d3eddfa64a7cc757f0fc9b74e3c49b3
parent5ec3c49c22c3448cd0583be74512129c221cd030 (diff)
Test reading of table cells when non-cells are present
-rw-r--r--lib/docx/body-reader.js1
-rw-r--r--test/docx/body-reader.tests.js38
2 files changed, 38 insertions, 1 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js
index e6a70e2..b3aea00 100644
--- a/lib/docx/body-reader.js
+++ b/lib/docx/body-reader.js
@@ -532,6 +532,7 @@ function BodyReader(options) {
});
});
if (unexpectedNonCells) {
+ removeVMergeProperties(rows);
return elementResultWithMessages(rows, [warning(
"unexpected non-cell element in table row, cell merging may be incorrect"
)]);
diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js
index f6c986f..4fbea03 100644
--- a/test/docx/body-reader.tests.js
+++ b/test/docx/body-reader.tests.js
@@ -1323,7 +1323,9 @@ test("warning if non-row in table", function() {
])
])
]);
+
var result = readXmlElement(tableXml);
+
assert.deepEqual(result.value, new documents.Table([
new documents.TableRow([
new documents.TableCell([
@@ -1349,10 +1351,44 @@ test("warning if non-row in table", function() {
});
test("warning if non-cell in table row", function() {
+ // Include normal cells to ensure they're still read correctly.
var tableXml = new XmlElement("w:tbl", {}, [
- row(new XmlElement("w:p"))
+ row(
+ xml.element("w:tc", {}, [
+ xml.element("w:p", {}, [
+ runOfText("Cell 1")
+ ])
+ ]),
+ new XmlElement("w:p"),
+ xml.element("w:tc", {}, [
+ xml.element("w:p", {}, [
+ runOfText("Cell 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("Cell 1")
+ ])
+ ])
+ ]),
+ new documents.Paragraph([]),
+ new documents.TableCell([
+ new documents.Paragraph([
+ new documents.Run([
+ new documents.Text("Cell 2")
+ ])
+ ])
+ ])
+ ])
+ ]));
assert.deepEqual(result.messages, [warning("unexpected non-cell element in table row, cell merging may be incorrect")]);
});