Skip to content

Commit

Permalink
Don’t break rows with atomic cells
Browse files Browse the repository at this point in the history
Fix #1868.
  • Loading branch information
liZe committed Jul 11, 2024
1 parent 3a1259f commit 126abd3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
33 changes: 33 additions & 0 deletions tests/layout/test_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2145,6 +2145,39 @@ def test_table_page_breaks(html, rows, positions):
assert rows_position_y == positions


@assert_no_logs
def test_table_page_breaks_in_cell():
page1, page2 = render_pages('''
<style>
@page { size: 120px }
h1 { height: 30px}
td { line-height: 40px }
table { table-layout: fixed; width: 100% }
</style>
<h1>Dummy title</h1>
<table>
<tr><td>r1c1l1</td><td>r1c2l1</td></tr>
<tr><td>r2c1l1</td><td style="break-inside: avoid">r2c2l1<br>r2c2l2</td></tr>
<tr><td>r3c1l1</td><td>r3l1</td></tr>
</table>
''')
html, = page1.children
body, = html.children
h1, table_wrapper = body.children
table, = table_wrapper.children
group, = table.children
row, = group.children
assert len(row.children) == 2

html, = page2.children
body, = html.children
table_wrapper, = body.children
table, = table_wrapper.children
group, = table.children
row1, row2 = group.children
assert len(row1.children) == len(row2.children) == 2


@assert_no_logs
def test_table_page_breaks_complex_1():
pages = render_pages('''
Expand Down
9 changes: 7 additions & 2 deletions weasyprint/layout/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,13 @@ def group_layout(group, position_y, bottom_space, page_is_empty, skip_stack):
new_row_children.append(cell)

if resume_at and not page_is_empty:
if avoid_page_break(row.style['break_inside'], context):
# Don’t break in row with break-inside: avoid, abort row.
# Avoid break when "break-inside: avoid" is set on row or any
# on its cells.
avoid_break = (
avoid_page_break(row.style['break_inside'], context) or any(
avoid_page_break(cell.style['break_inside'], context)
for cell in row.children))
if avoid_break:
resume_at = {index_row: {}}
remove_placeholders(
context, new_row_children, absolute_boxes, fixed_boxes)
Expand Down

0 comments on commit 126abd3

Please sign in to comment.