mirror of
https://github.com/Kozea/WeasyPrint.git
synced 2024-10-05 00:21:15 +03:00
Handle the combined selectors with pseudo-elements
This commit is contained in:
parent
7167c3e637
commit
016befd1af
@ -351,14 +351,26 @@ def selector_to_xpath(selector):
|
||||
# cssselect.CSSSelector() will raise a cssselect.ExpressionError.
|
||||
# - The selector has no pseudo-element and is supported by
|
||||
# `cssselect.CSSSelector`.
|
||||
if isinstance(parsed_selector, cssselect.Pseudo) \
|
||||
and parsed_selector.ident in PSEUDO_ELEMENTS:
|
||||
pseudo_type = str(parsed_selector.ident)
|
||||
# Remove the pseudo-element from the selector
|
||||
parsed_selector = parsed_selector.element
|
||||
if isinstance(parsed_selector, cssselect.CombinedSelector):
|
||||
simple_selector = parsed_selector.subselector
|
||||
if isinstance(simple_selector, cssselect.Pseudo) \
|
||||
and simple_selector.ident in PSEUDO_ELEMENTS:
|
||||
pseudo_type = str(simple_selector.ident)
|
||||
# Remove the pseudo-element from the selector
|
||||
parsed_selector.subselector = simple_selector.element
|
||||
else:
|
||||
# No pseudo-element or invalid selector.
|
||||
pseudo_type = None
|
||||
else:
|
||||
# No pseudo-element or invalid selector.
|
||||
pseudo_type = None
|
||||
if isinstance(parsed_selector, cssselect.Pseudo) \
|
||||
and parsed_selector.ident in PSEUDO_ELEMENTS:
|
||||
pseudo_type = str(parsed_selector.ident)
|
||||
# Remove the pseudo-element from the selector
|
||||
parsed_selector = parsed_selector.element
|
||||
else:
|
||||
# No pseudo-element or invalid selector.
|
||||
pseudo_type = None
|
||||
|
||||
selector_callable = cssselect.CSSSelector(parsed_selector)
|
||||
result = (pseudo_type, selector_callable)
|
||||
|
||||
|
@ -18,6 +18,9 @@
|
||||
body > h1:first-child {
|
||||
background-image: url(logo_small.png);
|
||||
}
|
||||
h1 ~ p ~ ul a:after {
|
||||
background: red;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
@ -71,11 +71,11 @@ def test_find_stylesheets():
|
||||
|
||||
rules = list(rule for sheet in sheets
|
||||
for rule in css.effective_rules(sheet, 'print'))
|
||||
assert len(rules) == 9
|
||||
assert len(rules) == 10
|
||||
# Also test appearance order
|
||||
assert [rule.selectorText for rule in rules] \
|
||||
== ['a', 'li', 'p', 'ul', 'li', 'a:after', ':first', 'ul',
|
||||
'body > h1:first-child']
|
||||
'body > h1:first-child', 'h1 ~ p ~ ul a:after']
|
||||
|
||||
|
||||
@assert_no_logs
|
||||
@ -179,6 +179,8 @@ def test_annotate_document():
|
||||
# The href attr should be as in the source, not made absolute.
|
||||
assert after.content == [
|
||||
('STRING', ' ['), ('STRING', 'home.html'), ('STRING', ']')]
|
||||
color = after.background_color
|
||||
assert (color.red, color.green, color.blue, color.alpha) == (255, 0, 0, 1)
|
||||
|
||||
# TODO much more tests here: test that origin and selector precedence
|
||||
# and inheritance are correct, ...
|
||||
|
Loading…
Reference in New Issue
Block a user