1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-04 07:57:52 +03:00

Make footnote call’s style inherit from the footnote’s parent

There’s nothing in the specification about that, but here’s what we do now:

- The style of a footnote inherits from its parent’s style, it doesn’t inherit
from the footnote area’s style. That’s how cascade works for real elements, and
there’s no real reason or way to avoid this.

- The style of a footnote marker inherits from the footnote style. The marker
is just like a ::before block regarding to its style, even if it is actually
put before the footnote element in the footnote body.

- The style of a footnote call inherits from the footnote parent’s style. It
doesn’t inherit from the footnote’s style, that’s actually applied to the
footnote and inherited by its marker.

This way, we keep the "normal" cascade for "normal" elements, and have
everything else being quite obvious.

The 1st point is annoying in real-life use cases, because we’d really like to
see the footnote’s style inherit from the footnote area’s style. But we really
don’t want to break the cascade. Do we? No, we don’t.

The 3rd point is probably the most disturbing one, mainly because
.footnote::footnote-call doesn’t match the call: to match a footnote call in a
paragraph, for example, we have to use p::footnote-call instead.
This commit is contained in:
Guillaume Ayoub 2021-12-07 14:46:26 +01:00
parent 6f190a2f20
commit 7aa0860185

View File

@ -180,9 +180,24 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
children.append(boxes.TextBox.anonymous_from(box, text))
for child_element in element:
children.extend(element_to_box(
child_boxes = element_to_box(
child_element, style_for, get_image_from_uri, base_url,
target_collector, counter_style, footnotes, state))
target_collector, counter_style, footnotes, state)
if child_boxes and child_boxes[0].style['float'] == 'footnote':
footnote = child_boxes[0]
footnote.style['float'] = 'none'
footnotes.append(footnote)
call_style = style_for(element, 'footnote-call')
footnote_call = make_box(
f'{element.tag}::footnote-call', call_style, [], element)
footnote_call.children = content_to_boxes(
call_style, footnote_call, quote_depth, counter_values,
get_image_from_uri, target_collector, counter_style)
footnote_call.footnote = footnote
child_boxes = [footnote_call]
children.extend(child_boxes)
text = child_element.tail
if text:
text_box = boxes.TextBox.anonymous_from(box, text)
@ -190,6 +205,7 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
children[-1].text += text_box.text
else:
children.append(text_box)
children.extend(before_after_to_box(
element, 'after', state, style_for, get_image_from_uri,
target_collector, counter_style))
@ -222,10 +238,7 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
box.children.append(boxes.TextBox.anonymous_from(box, ''))
if style['float'] == 'footnote':
style['float'] = 'none'
counter_values['footnote'][-1] += 1
# TODO: footnote body style should inherit from footnotes area style
marker_style = style_for(element, 'footnote-marker')
marker = make_box(
f'{element.tag}::footnote-marker', marker_style, [], element)
@ -234,16 +247,6 @@ def element_to_box(element, style_for, get_image_from_uri, base_url,
target_collector, counter_style)
box.children.insert(0, marker)
box = create_anonymous_boxes(box)
footnotes.append(box)
# TODO: footnote call style should inherit from footnotes parent style
call_style = style_for(element, 'footnote-call')
box = make_box(
f'{element.tag}::footnote-call', call_style, [], element)
box.children = content_to_boxes(
call_style, box, quote_depth, counter_values, get_image_from_uri,
target_collector, counter_style)
box.footnote = footnotes[-1]
# Specific handling for the element. (eg. replaced element)
return html.handle_element(element, box, get_image_from_uri, base_url)