Skip to content

Commit 8ca702c

Browse files
committed
Test reading of table cells when non-cells are present
1 parent 5ec3c49 commit 8ca702c

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/docx/body-reader.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,7 @@ function BodyReader(options) {
532532
});
533533
});
534534
if (unexpectedNonCells) {
535+
removeVMergeProperties(rows);
535536
return elementResultWithMessages(rows, [warning(
536537
"unexpected non-cell element in table row, cell merging may be incorrect"
537538
)]);

test/docx/body-reader.tests.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1323,7 +1323,9 @@ test("warning if non-row in table", function() {
13231323
])
13241324
])
13251325
]);
1326+
13261327
var result = readXmlElement(tableXml);
1328+
13271329
assert.deepEqual(result.value, new documents.Table([
13281330
new documents.TableRow([
13291331
new documents.TableCell([
@@ -1349,10 +1351,44 @@ test("warning if non-row in table", function() {
13491351
});
13501352

13511353
test("warning if non-cell in table row", function() {
1354+
// Include normal cells to ensure they're still read correctly.
13521355
var tableXml = new XmlElement("w:tbl", {}, [
1353-
row(new XmlElement("w:p"))
1356+
row(
1357+
xml.element("w:tc", {}, [
1358+
xml.element("w:p", {}, [
1359+
runOfText("Cell 1")
1360+
])
1361+
]),
1362+
new XmlElement("w:p"),
1363+
xml.element("w:tc", {}, [
1364+
xml.element("w:p", {}, [
1365+
runOfText("Cell 2")
1366+
])
1367+
])
1368+
)
13541369
]);
1370+
13551371
var result = readXmlElement(tableXml);
1372+
1373+
assert.deepEqual(result.value, new documents.Table([
1374+
new documents.TableRow([
1375+
new documents.TableCell([
1376+
new documents.Paragraph([
1377+
new documents.Run([
1378+
new documents.Text("Cell 1")
1379+
])
1380+
])
1381+
]),
1382+
new documents.Paragraph([]),
1383+
new documents.TableCell([
1384+
new documents.Paragraph([
1385+
new documents.Run([
1386+
new documents.Text("Cell 2")
1387+
])
1388+
])
1389+
])
1390+
])
1391+
]));
13561392
assert.deepEqual(result.messages, [warning("unexpected non-cell element in table row, cell merging may be incorrect")]);
13571393
});
13581394

0 commit comments

Comments
 (0)