1
1
mirror of https://github.com/Kozea/WeasyPrint.git synced 2024-10-05 00:21:15 +03:00

Merge remote-tracking branch 'origin/master' into pydyf

This commit is contained in:
Guillaume Ayoub 2020-05-23 21:45:45 +02:00
commit 8e9e6b6bfe
2 changed files with 9 additions and 28 deletions

View File

@ -518,9 +518,6 @@ def _content_list(computer, values):
(attr,) + value[1][1:]))
else:
computed_value = value
if computer['target_collector'] and computed_value:
computer['target_collector'].collect_computed_target(
computed_value[1][0])
if computed_value is None:
LOGGER.warning('Unable to compute %s\'s value for content: %s' % (
computer['element'], ', '.join(str(item) for item in value)))

View File

@ -6,7 +6,7 @@
The TargetCollector is a structure providing required targets'
counter_values and stuff needed to build pending targets later,
when the layout of all targetted anchors has been done.
when the layout of all targeted anchors has been done.
"""
@ -18,7 +18,7 @@ from ..logger import LOGGER
class TargetLookupItem:
"""Item controlling pending targets and page based target counters.
Collected in the TargetCollector's ``items``.
Collected in the TargetCollector's ``target_lookup_items``.
"""
def __init__(self, state='pending'):
@ -83,9 +83,6 @@ class TargetCollector:
# to call the needed parse_again functions.
self.had_pending_targets = False
# List of anchors that have already been seen during parsing.
self.existing_anchors = []
def anchor_name_from_token(self, anchor_token):
"""Get anchor name from string or uri token."""
if anchor_token[0] == 'string' and anchor_token[1].startswith('#'):
@ -94,23 +91,13 @@ class TargetCollector:
return anchor_token[1][1]
def collect_anchor(self, anchor_name):
"""Store ``anchor_name`` in ``existing_anchors``."""
"""Create a TargetLookupItem for the given `anchor_name``."""
if anchor_name and isinstance(anchor_name, str):
if anchor_name in self.existing_anchors:
if self.target_lookup_items.get(anchor_name) is not None:
LOGGER.warning('Anchor defined twice: %s', anchor_name)
else:
self.existing_anchors.append(anchor_name)
def collect_computed_target(self, anchor_token):
"""Store a computed internal target's ``anchor_name``.
``anchor_name`` must not start with '#' and be already unquoted.
"""
anchor_name = self.anchor_name_from_token(anchor_token)
if anchor_name:
self.target_lookup_items.setdefault(
anchor_name, TargetLookupItem())
self.target_lookup_items.setdefault(
anchor_name, TargetLookupItem())
def lookup_target(self, anchor_token, source_box, css_token, parse_again):
"""Get a TargetLookupItem corresponding to ``anchor_token``.
@ -125,12 +112,9 @@ class TargetCollector:
anchor_name, TargetLookupItem('undefined'))
if item.state == 'pending':
if anchor_name in self.existing_anchors:
self.had_pending_targets = True
item.parse_again_functions.setdefault(
(source_box, css_token), parse_again)
else:
item.state = 'undefined'
self.had_pending_targets = True
item.parse_again_functions.setdefault(
(source_box, css_token), parse_again)
if item.state == 'undefined':
LOGGER.error(