diff --git a/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-1-snap.png b/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-1-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..5f890b2f25d818eb227b5a6718969b7f34b94e86 Binary files /dev/null and b/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-1-snap.png differ diff --git a/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-2-snap.png b/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-2-snap.png new file mode 100644 index 0000000000000000000000000000000000000000..f1e866d710baa1bc3dc438f74aa88f133c92c1d5 Binary files /dev/null and b/specs/breaks/table/__image_snapshots_linux__/avoid-break-rowspan-spec-js-breaks-table-avoid-break-rowspan-should-create-a-pdf-2-snap.png differ diff --git a/specs/breaks/table/avoid-break-rowspan.html b/specs/breaks/table/avoid-break-rowspan.html new file mode 100644 index 0000000000000000000000000000000000000000..d51694baa42e645fb6cb0f9b415a6a420ee9b14d --- /dev/null +++ b/specs/breaks/table/avoid-break-rowspan.html @@ -0,0 +1,223 @@ + + + + table-avoid-break-rowspan + + + + + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
idfirst_namelast_nameemail + score
1MagdalenHoltawayFlowdesk37.67
2OlenkaTuckettSubin
3TownyCalverleyFintone
4MaribethCaskieTresom13.64
5RoldanWhithamFlowdesk
6MelodyGentleAsoka
7AidaHoltumBigtax84.10
8AngeliaO'FarrellBamity
9PuffStennetAerified
10CarmelEnnionKanlam59.44
11PhyllidaSarraToughjoyfax
12DulcyLamb-shineTresom
13PiggyJuniferBitchip23.64
14AdriannaMillichapIt
15CelesteMilletonDaltfresh
16TedSlydeTreeflex74.64
17MaureneSylvesterTres-Zap
18MonteTingleyRedhold
19LouiseMcMichellLatlux18.86
20TurnerMcQuirterKeylex
21AlvinEmilienCardguard
22JoanneObeyRegrant25.32
23LorneLescopHome Ing
24ZaraJillettMatsoft
25DelmoreHellisRegrant42.33
+
+
+ + diff --git a/specs/breaks/table/avoid-break-rowspan.spec.js b/specs/breaks/table/avoid-break-rowspan.spec.js new file mode 100644 index 0000000000000000000000000000000000000000..695288191122ec06a740d10f09d9f702e585e0c0 --- /dev/null +++ b/specs/breaks/table/avoid-break-rowspan.spec.js @@ -0,0 +1,23 @@ +const TIMEOUT = 10000; + +describe("breaks-table-avoid-break-rowspan", () => { + let page; + beforeAll(async () => { + page = await loadPage("breaks/table/avoid-break-rowspan.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); + }); + } +}); diff --git a/src/chunker/layout.js b/src/chunker/layout.js index c5b1671ade6edafefcbadb8108ce4adb706cdb17..8a667e53d9905bb574c7017a64989165edb88764 100644 --- a/src/chunker/layout.js +++ b/src/chunker/layout.js @@ -496,6 +496,40 @@ class Layout { br = node.tagName === "BR" || node.tagName === "WBR"; } + let tableRow; + if (node.nodeName === "TR") { + tableRow = node; + } else { + tableRow = parentOf(node, "TR", rendered); + } + if (tableRow) { + // Check if the node is inside a row with a rowspan + const table = parentOf(tableRow, "TABLE", rendered); + if (table) { + let columnCount = 0; + for (const cell of Array.from(table.rows[0].cells)) { + columnCount += parseInt(cell.getAttribute("COLSPAN") || "1"); + } + if (tableRow.cells.length !== columnCount) { + let previousRow = tableRow.previousSibling; + let previousRowColumnCount; + while (previousRow !== null) { + previousRowColumnCount = 0; + for (const cell of Array.from(previousRow.cells)) { + previousRowColumnCount += parseInt(cell.getAttribute("COLSPAN") || "1"); + } + if (previousRowColumnCount === columnCount) { + break; + } + previousRow = previousRow.previousSibling; + } + if (previousRowColumnCount === columnCount) { + prev = previousRow; + } + } + } + } + if (prev) { range = document.createRange(); range.selectNode(prev);