Skip to content

Commit 5ec3c49

Browse files
committed
Test reading of table rows when non-rows are present
1 parent 033466f commit 5ec3c49

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

lib/docx/body-reader.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,7 @@ function BodyReader(options) {
521521
return row.type !== documents.types.tableRow;
522522
});
523523
if (unexpectedNonRows) {
524+
removeVMergeProperties(rows);
524525
return elementResultWithMessages(rows, [warning(
525526
"unexpected non-row element in table, cell merging may be incorrect"
526527
)]);
@@ -563,6 +564,14 @@ function BodyReader(options) {
563564
return elementResult(rows);
564565
}
565566

567+
function removeVMergeProperties(rows) {
568+
rows.forEach(function(row) {
569+
row.children.forEach(function(cell) {
570+
delete cell._vMerge;
571+
});
572+
});
573+
}
574+
566575
function readDrawingElement(element) {
567576
var blips = element
568577
.getElementsByTagName("a:graphic")

test/docx/body-reader.tests.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,10 +1305,46 @@ test("when row is marked as deleted in row properties then row is ignored", func
13051305
});
13061306

13071307
test("warning if non-row in table", function() {
1308+
// Include normal rows to ensure they're still read correctly.
13081309
var tableXml = new XmlElement("w:tbl", {}, [
1309-
new XmlElement("w:p")
1310+
xml.element("w:tr", {}, [
1311+
xml.element("w:tc", {}, [
1312+
xml.element("w:p", {}, [
1313+
runOfText("Row 1")
1314+
])
1315+
])
1316+
]),
1317+
new XmlElement("w:p"),
1318+
xml.element("w:tr", {}, [
1319+
xml.element("w:tc", {}, [
1320+
xml.element("w:p", {}, [
1321+
runOfText("Row 2")
1322+
])
1323+
])
1324+
])
13101325
]);
13111326
var result = readXmlElement(tableXml);
1327+
assert.deepEqual(result.value, new documents.Table([
1328+
new documents.TableRow([
1329+
new documents.TableCell([
1330+
new documents.Paragraph([
1331+
new documents.Run([
1332+
new documents.Text("Row 1")
1333+
])
1334+
])
1335+
])
1336+
]),
1337+
new documents.Paragraph([]),
1338+
new documents.TableRow([
1339+
new documents.TableCell([
1340+
new documents.Paragraph([
1341+
new documents.Run([
1342+
new documents.Text("Row 2")
1343+
])
1344+
])
1345+
])
1346+
])
1347+
]));
13121348
assert.deepEqual(result.messages, [warning("unexpected non-row element in table, cell merging may be incorrect")]);
13131349
});
13141350

0 commit comments

Comments
 (0)