Commit dbfd60b6 authored by Guillaume's avatar Guillaume
Browse files

resolves #239 duplicate columns with rowspan when a table is chunked

parent beaa5c8a
<!DOCTYPE html PUBLIC>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>rowspan-table</title>
<script src="../../../dist/paged.polyfill.js"></script>
<style>
@page {
size: 500px 300px;
border: 1px solid #cfc2c2;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
tr, td {
break-inside: avoid;
}
</style>
</head>
<body>
<table>
<tbody>
<tr>
<td rowspan="4">1</td>
<td rowspan="4">This is a long description</td>
<td>First row, third column</td>
</tr>
<tr>
<td>Second row, third column</td>
</tr>
<tr>
<td>Third row, third column</td>
</tr>
<tr>
<td>Fourth row, third column</td>
</tr>
</tbody>
</table>
</body>
</html>
const TIMEOUT = 10000;
describe("rowspan table", () => {
let page;
beforeAll(async () => {
page = await loadPage("splits/tables/rowspan-table.html");
return page.rendered;
}, TIMEOUT);
afterAll(async () => {
if (!DEBUG) {
await page.close();
}
});
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
expect(pdf).toMatchPDFSnapshot(1);
expect(pdf).toMatchPDFSnapshot(2);
});
}
});
......@@ -140,6 +140,29 @@ export function rebuildAncestors(node) {
let fragment = document.createDocumentFragment();
// Handle rowspan on table
if (node.nodeName === "TR") {
let previousRow = node.previousElementSibling;
let previousRowDistance = 1;
while (previousRow) {
// previous row has more columns, might indicate a rowspan.
if (previousRow.childElementCount > node.childElementCount) {
for (let j = previousRow.children.length - 1; j >= 0; j--) {
let column = previousRow.children[j];
if (column.rowSpan && column.rowSpan > previousRowDistance) {
const duplicatedColumn = column.cloneNode(true);
// Adjust rowspan value
duplicatedColumn.rowSpan = column.rowSpan - previousRowDistance;
// Add the column to the row
node.prepend(duplicatedColumn);
}
}
}
previousRow = previousRow.previousElementSibling;
previousRowDistance++;
}
}
// Gather all ancestors
let element = node;
while(element.parentNode && element.parentNode.nodeType === 1) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment