Commit 89ad08e3 authored by Fred Chasen's avatar Fred Chasen

Merge branch 'table-rowspan-break' into 'master'

Break on table row that does not contains rowspan

See merge request !149
parents 679cfd10 aac7c38e
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<script src="../../../dist/paged.polyfill.js"></script>
@page {
size: A5;
margin: 1cm;
table {
border-collapse: collapse;
border-spacing: 0;
tr {
break-inside: avoid;
.table td, .table th {
border: 1px solid #dbdbdb;
padding: .5em .75em;
vertical-align: top;
/* interface */
@media screen {
body {
background-color: whitesmoke;
.pagedjs_page {
margin-bottom: 20px;
flex: none;
box-shadow: 0 0 0 1px rgba(0, 0,0,0.2);
background-color: white;
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<table class="table is-bordered">
<th colspan="2">email + score</th>
<td rowspan="3">37.67</td>
<td rowspan="3">13.64</td>
<td rowspan="3">84.10</td>
<td rowspan="3">59.44</td>
<td rowspan="3">23.64</td>
<td rowspan="3">74.64</td>
<td rowspan="3">18.86</td>
<td rowspan="3">25.32</td>
<td>Home Ing</td>
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;
afterAll(async () => {
if (!DEBUG) {
await page.close();
if (!DEBUG) {
it("should create a pdf", async () => {
let pdf = await page.pdf(PDF_SETTINGS);
......@@ -498,6 +498,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) {
previousRow = previousRow.previousSibling;
if (previousRowColumnCount === columnCount) {
prev = previousRow;
if (prev) {
range = document.createRange();
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