Skip to content

Commit

Permalink
Respect break-inside: avoid for flex items
Browse files Browse the repository at this point in the history
Fix #2183.
  • Loading branch information
liZe committed Jun 14, 2024
1 parent 64b3568 commit e7c44e5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
23 changes: 23 additions & 0 deletions tests/layout/test_flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,26 @@ def test_flex_percent_height_auto():
<div class="a"">
<div class="b"></div>
</div>''')


@assert_no_logs
def test_flex_break_inside_avoid():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/2183
page1, page2= render_pages('''
<style>
@font-face { src: url(weasyprint.otf); font-family: weasyprint }
@page { size: 6px 4px }
html { font-family: weasyprint; font-size: 2px }
</style>
<article style="display: flex; flex-wrap: wrap">
<div>ABC</div>
<div style="break-inside: avoid">abc def</div>
</article>''')
html, = page1.children
body, = html.children
article, = body.children
div, = article.children
html, = page2.children
body, = html.children
article, = body.children
div, = article.children
7 changes: 5 additions & 2 deletions weasyprint/layout/flex.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,9 +852,12 @@ def flex_layout(context, box, bottom_space, skip_stack, containing_block,
if new_child is None:
if resume_at:
index, = resume_at
if index:
resume_at = {index + i - 1: None}
index -= 1
else:
index = 0
resume_at = {index + i: None}
else:
page_is_empty = False
box.children.append(new_child)
if child_resume_at is not None:
if original_skip_stack:
Expand Down

0 comments on commit e7c44e5

Please sign in to comment.