Skip to content

Commit

Permalink
Correctly set target counters in pages’ absolute elements
Browse files Browse the repository at this point in the history
Fix #1747.
  • Loading branch information
liZe committed Oct 24, 2022
1 parent 7767b53 commit cb870ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
25 changes: 25 additions & 0 deletions tests/test_target.py
Expand Up @@ -157,3 +157,28 @@ def test_target_float():
text_box, after = inline.children
assert text_box.text == 'link'
assert after.children[0].children[0].text == '1'


@assert_no_logs
def test_target_absolute():
document = FakeHTML(string='''
<style>
a::after {
content: target-counter('#h', page);
}
div {
position: absolute;
}
</style>
<div><a id="span">link</a></div>
<h1 id="h">abc</h1>
''')
page, = document.render().pages
html, = page._page_box.children
body, = html.children
div, h1 = body.children
line, = div.children
inline, = line.children
text_box, after = inline.children
assert text_box.text == 'link'
assert after.children[0].text == '1'
5 changes: 4 additions & 1 deletion weasyprint/layout/page.py
@@ -1,6 +1,7 @@
"""Layout for pages and CSS3 margin boxes."""

import copy
from itertools import chain
from math import inf

from ..css import PageType, computed_from_cascaded
Expand Down Expand Up @@ -605,7 +606,9 @@ def make_page(context, root_box, page_type, resume_at, page_number,
context.finish_block_formatting_context(root_box)

page.children = [root_box, footnote_area]
descendants = page.descendants()
descendants = chain(page.descendants(), *(
child.descendants() if hasattr(child, 'descendants') else (child,)
for child in positioned_boxes))

# Update page counter values
_standardize_page_based_counters(style, None)
Expand Down

0 comments on commit cb870ae

Please sign in to comment.