Skip to content

Commit

Permalink
Merge pull request #1509 from Kozea/footnotes
Browse files Browse the repository at this point in the history
Support footnotes
  • Loading branch information
liZe committed Dec 11, 2021
2 parents 8ae0917 + 87e4765 commit f124e31
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 197 deletions.
13 changes: 8 additions & 5 deletions docs/api_reference.rst
Expand Up @@ -391,16 +391,19 @@ to their position in the document:
You can also use `running elements`_ to put HTML boxes into the page margins
(but the ``start`` parameter of ``element()`` is not supported).

The other features of GCPM are **not** implemented:
Footnotes_ are supported. You can put a box in the footnote area using the
``float: footnote`` property. Footnote markers and footnote calls can be
defined using the ``::footnote-marker`` and ``::footnote-call``
pseudo-elements. You can also change the way footnotes are displayed using the
``footnote-display`` property (``compact`` is not supported), and influence
over the rendering of difficult pages with ``footnote-policy``.

- footnotes (``float: footnote``, ``footnote-display``, ``footnote`` counter,
``::footnote-call``, ``::footnote-marker``, ``@footnote`` rule,
``footnote-policy``);
- page groups (``:nth(X of pagename)`` pseudo-class).
Page groups (``:nth(X of pagename)`` pseudo-class) are not supported.

.. _CSS Generated Content for Paged Media Module: http://www.w3.org/TR/css-gcpm-3/
.. _Page selectors: https://www.w3.org/TR/css-gcpm-3/#document-page-selectors
.. _running elements: https://www.w3.org/TR/css-gcpm-3/#running-elements
.. _Footnotes: https://www.w3.org/TR/css-gcpm-3/#footnotes

CSS Generated Content Module Level 3
++++++++++++++++++++++++++++++++++++
Expand Down
134 changes: 134 additions & 0 deletions tests/draw/test_footnotes.py
@@ -0,0 +1,134 @@
"""
weasyprint.tests.test_draw.test_footnotes
-----------------------------------------
Test how footnotes are drawn.
"""

from ..testing_utils import assert_no_logs
from . import assert_pixels


@assert_no_logs
def test_inline_footnote():
assert_pixels('span_footnote', 9, 7, '''
RRRRRRRR_
RRRRRRRR_
_________
_________
_________
RRRRRRRR_
RRRRRRRR_
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 7px;
background: white;
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span {
float: footnote;
}
</style>
<div>abc<span>de</span></div>''')


@assert_no_logs
def test_block_footnote():
assert_pixels('div_footnote', 9, 7, '''
RRRRRRRR_
RRRRRRRR_
_________
_________
_________
RRRRRRRR_
RRRRRRRR_
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 7px;
background: white;
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
div.footnote {
float: footnote;
}
</style>
<div>abc<div class="footnote">de</div></div>''')


@assert_no_logs
def test_long_footnote():
assert_pixels('long_footnote', 9, 7, '''
RRRRRRRR_
RRRRRRRR_
_________
RRRRRRRR_
RRRRRRRR_
RR_______
RR_______
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 7px;
background: white;
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span {
float: footnote;
}
</style>
<div>abc<span>de f</span></div>''')


@assert_no_logs
def test_footnote_margin():
assert_pixels('footnote_margin', 9, 7, '''
RRRRRRRR_
RRRRRRRR_
_________
_________
_RRRRRR__
_RRRRRR__
_________
''', '''
<style>
@font-face {src: url(weasyprint.otf); font-family: weasyprint}
@page {
size: 9px 7px;
background: white;
@footnote {
margin: 1px;
}
}
div {
color: red;
font-family: weasyprint;
font-size: 2px;
line-height: 1;
}
span {
float: footnote;
}
</style>
<div>abc<span>d</span></div>''')
2 changes: 1 addition & 1 deletion tests/layout/test_block.py
Expand Up @@ -708,7 +708,7 @@ def test_box_decoration_break_slice_bottom_padding(): # pragma: no cover
# break between a parent and its last child, put last child on next page.
# TODO: at the end of block_container_layout, we should check that the box
# with its bottom border/padding doesn't cross the bottom line. If it does,
# we should re-render the box with a max_position_y including the bottom
# we should re-render the box with a bottom_space including the bottom
# border/padding.
page_1, page_2 = render_pages('''
<style>
Expand Down

0 comments on commit f124e31

Please sign in to comment.