From e7c44e5fcdd5c7a1bf9b453c772d52c9a9ac51c4 Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Fri, 14 Jun 2024 12:13:27 +0200 Subject: [PATCH] Respect break-inside: avoid for flex items Fix #2183. --- tests/layout/test_flex.py | 23 +++++++++++++++++++++++ weasyprint/layout/flex.py | 7 +++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/tests/layout/test_flex.py b/tests/layout/test_flex.py index 511bde633..6344b8f2a 100644 --- a/tests/layout/test_flex.py +++ b/tests/layout/test_flex.py @@ -576,3 +576,26 @@ def test_flex_percent_height_auto():
''') + + +@assert_no_logs +def test_flex_break_inside_avoid(): + # Regression test for https://github.com/Kozea/WeasyPrint/issues/2183 + page1, page2= render_pages(''' + +
+
ABC
+
abc def
+
''') + html, = page1.children + body, = html.children + article, = body.children + div, = article.children + html, = page2.children + body, = html.children + article, = body.children + div, = article.children diff --git a/weasyprint/layout/flex.py b/weasyprint/layout/flex.py index 5d3cef502..137906889 100644 --- a/weasyprint/layout/flex.py +++ b/weasyprint/layout/flex.py @@ -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: