Skip to content

Commit

Permalink
Don't display absolutes when their parents have no other children
Browse files Browse the repository at this point in the history
If a parent box can only display absolute boxes at the bottom of the page, but
has other children that have to be drawn on the next page, keep the absolute
boxes for the next page too. It's at least very useful for markers.

Fix #945.
  • Loading branch information
liZe committed Sep 18, 2019
1 parent fbf3467 commit 8abc39d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions weasyprint/layout/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,15 @@ def block_container_layout(context, box, max_position_y, skip_stack,
# else:
# ignore this 'avoid' and break anyway.

if all(child.is_absolutely_positioned()
for child in new_children):
# This box has only rendered absolute children, keep them
# for the next page. This is for example useful for list
# markers.
remove_placeholders(
new_children, absolute_boxes, fixed_boxes)
new_children = []

if new_children:
resume_at = (index, None)
break
Expand Down
30 changes: 30 additions & 0 deletions weasyprint/tests/test_layout/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,33 @@ def test_lists_empty_item():
unordered_list, = body.children
li1, li2, li3 = unordered_list.children
assert li1.position_y != li2.position_y != li3.position_y


def test_lists_page_break():
# Regression test for https://github.com/Kozea/WeasyPrint/issues/945
page1, page2 = parse('''
<style>
@font-face { src: url(AHEM____.TTF); font-family: ahem }
@page { size: 300px 100px }
ul { font-size: 30px; font-family: ahem; margin: 0 }
</style>
<ul>
<li>a</li>
<li>a</li>
<li>a</li>
<li>a</li>
</ul>
''')
html, = page1.children
body, = html.children
ul, = body.children
assert len(ul.children) == 3
for li in ul.children:
assert len(li.children) == 2

html, = page2.children
body, = html.children
ul, = body.children
assert len(ul.children) == 1
for li in ul.children:
assert len(li.children) == 2

0 comments on commit 8abc39d

Please sign in to comment.