Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix named pages inheritence #1899

Merged
merged 2 commits into from
Aug 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/layout/test_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,42 @@ def test_page_names_9():
assert article.element_tag == 'article'


@assert_no_logs
def test_page_names_10():
pages = render_pages('''
<style>
#running { position: running(running); }
#fixed { position: fixed; }
@page { size: 200px 200px; @top-center { content: element(header); }}
section { page: small; }
@page small { size: 100px 100px; }
.pagebreak { break-after: page; }
</style>
<div id="running">running</div>
<div id="fixed">fixed</div>
<section>
<h1>text</h1>
<div class="pagebreak"></div>
<article>text</article>
</section>
''')
page1, page2 = pages

assert (page1.width, page1.height) == (100, 100)
html, runing = page1.children
body, = html.children
fixed, section, = body.children
h1, pagebreak = section.children
assert h1.element_tag == 'h1'

assert (page2.width, page2.height) == (100, 100)
html, running = page2.children
fixed, body = html.children
section, = body.children
article, = section.children
assert article.element_tag == 'article'


@assert_no_logs
@pytest.mark.parametrize('style, line_counts', (
('orphans: 2; widows: 2', [4, 3]),
Expand Down
12 changes: 8 additions & 4 deletions weasyprint/formatting_structure/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,13 +377,17 @@ def get_wrapped_table(self):

def page_values(self):
start_value, end_value = super().page_values()
if self.children:
if len(self.children) == 1:
page_values = self.children[0].page_values()
children = [
c for c in self.children
if not (c.is_absolutely_positioned() or c.is_running())
]
if children:
if len(children) == 1:
page_values = children[0].page_values()
start_value = page_values[0] or start_value
end_value = page_values[1] or end_value
else:
start_box, end_box = self.children[0], self.children[-1]
start_box, end_box = children[0], children[-1]
start_value = start_box.page_values()[0] or start_value
end_value = end_box.page_values()[1] or end_value
return start_value, end_value
Expand Down