Skip to content

Commit

Permalink
Handle break-inside: avoid in tr
Browse files Browse the repository at this point in the history
Fix #1547.
  • Loading branch information
liZe committed Jan 25, 2022
1 parent 8b0f147 commit 563ee6f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/layout/test_table.py
Expand Up @@ -2054,6 +2054,40 @@ def test_table_html_tag():
''',
[1, 2],
[30, 0, 40]),
('''
<style>
@page { size: 120px }
h1 { height: 30px}
td { line-height: 40px }
table { table-layout: fixed; width: 100%; orphans: 1; widows: 1 }
</style>
<h1>Dummy title</h1>
<table>
<tr><td>r1l1</td></tr>
<tr style="break-inside: avoid"><td>r2l1<br>r2l2</td></tr>
<tr><td>r3l1</td></tr>
</table>
''',
[1, 2],
[30, 0, 80]),
('''
<style>
@page { size: 120px }
h1 { height: 30px}
td { line-height: 40px }
table { table-layout: fixed; width: 100%; orphans: 1; widows: 1 }
</style>
<h1>Dummy title</h1>
<table>
<tbody>
<tr><td>r1l1</td></tr>
<tr style="break-inside: avoid"><td>r2l1<br>r2l2</td></tr>
</tbody>
<tr><td>r3l1</td></tr>
</table>
''',
[1, 2],
[30, 0, 80]),
))
def test_table_page_breaks(html, rows, positions):
pages = render_pages(html)
Expand Down
5 changes: 5 additions & 0 deletions weasyprint/layout/table.py
Expand Up @@ -194,6 +194,11 @@ def group_layout(group, position_y, bottom_space, page_is_empty,
cell.height = max(cell.height, cell.computed_height)
new_row_children.append(cell)

if resume_at and not page_is_empty:
if row.style['break_inside'] in ('avoid', 'avoid-page'):
resume_at = {index_row: {}}
break

row = row.copy_with_children(new_row_children)

# Table height algorithm
Expand Down

0 comments on commit 563ee6f

Please sign in to comment.