Skip to content

Commit

Permalink
Merge pull request #1570 from aschmitz/fix-repeat-unlayout
Browse files Browse the repository at this point in the history
fix: more robustly handle unlayout'ing a footnote
  • Loading branch information
liZe authored Feb 26, 2022
2 parents 2087a69 + 1d7ddfd commit a969ec1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions tests/layout/test_footnotes.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def test_reported_footnote_3():
('p { break-inside: avoid }', '<br>e<br>f'),
('p { widows: 4 }', '<br>e<br>f'),
('p + p { break-before: avoid }', '</p><p>e<br>f'),
('p + p { break-before: avoid }', '<span>y</span><span>z</span></p><p>e'),
))
def test_footnote_area_after_call(css, tail):
pages = render_pages('''
Expand Down
16 changes: 10 additions & 6 deletions weasyprint/layout/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,16 @@ def layout_footnote(self, footnote):

def unlayout_footnote(self, footnote):
"""Remove a footnote from the layout and return it to the waitlist."""
self.footnotes.append(footnote)
if footnote in self.current_page_footnotes:
self.current_page_footnotes.remove(footnote)
else:
self.reported_footnotes.remove(footnote)
self._update_footnote_area()

# Handle unlayouting a footnote that hasn't been laid out yet (or has
# already been unlayout'd):
if footnote not in self.footnotes:
self.footnotes.append(footnote)
if footnote in self.current_page_footnotes:
self.current_page_footnotes.remove(footnote)
elif footnote in self.reported_footnotes:
self.reported_footnotes.remove(footnote)
self._update_footnote_area()

def report_footnote(self, footnote):
"""Mark a footnote as being moved to the next page."""
Expand Down

0 comments on commit a969ec1

Please sign in to comment.