Skip to content

Commit

Permalink
Merge branch '62.x'
Browse files Browse the repository at this point in the history
liZe committed May 22, 2024
2 parents 83641f3 + e6625ed commit e00e393
Showing 3 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ jobs:
- name: Install DejaVu, Pango and Ghostscript (MacOS)
if: matrix.os == 'macos-latest'
run: |
brew tap homebrew/cask-fonts
brew update
brew install --cask font-dejavu
brew install pango ghostscript
- name: Install DejaVu, Pango and Ghostscript (Windows)
2 changes: 2 additions & 0 deletions tests/css/test_nesting.py
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@
'p { div & { width: 10px } width: 20px }',
'div { & { & { p { & { width: 10px } } } } }',
'@media print { div { p { width: 10px } } }',
'div { em, p { width: 10px } }',
'p { a, div & { width: 10px } }',
))
def test_nesting_block(style):
page, = render_pages('''
43 changes: 25 additions & 18 deletions weasyprint/css/validation/__init__.py
Original file line number Diff line number Diff line change
@@ -149,26 +149,33 @@ def preprocess_declarations(base_url, declarations, prelude=None):
# Nested rule.
if prelude is None:
continue
declaration_prelude = declaration.prelude
if NESTING_SELECTOR in declaration.prelude:
# Replace & selector by parent.
declaration_prelude = []
for token in declaration.prelude:
if token == NESTING_SELECTOR:
declaration_prelude.extend(is_token)
else:
declaration_prelude.append(token)
else:
# No & selector, prepend parent.
is_token = (
LiteralToken(1, 1, ':'),
FunctionBlock(1, 1, 'is', prelude))
declaration_prelude = [
*is_token, WhitespaceToken(1, 1, ' '),
*declaration.prelude]
declaration_prelude = []
token_groups = [[]]
for token in declaration.prelude:
if token == ',':
token_groups.append([])
else:
token_groups[-1].append(token)
for token_group in token_groups:
if NESTING_SELECTOR in token_group:
# Replace & selector by parent.
for token in declaration.prelude:
if token == NESTING_SELECTOR:
declaration_prelude.extend(is_token)
else:
declaration_prelude.append(token)
else:
# No & selector, prepend parent.
is_token = (
LiteralToken(1, 1, ':'),
FunctionBlock(1, 1, 'is', prelude))
declaration_prelude.extend([
*is_token, WhitespaceToken(1, 1, ' '),
*token_group])
declaration_prelude.append(LiteralToken(1, 1, ','))
yield from preprocess_declarations(
base_url, parse_blocks_contents(declaration.content),
declaration_prelude)
declaration_prelude[:-1])

if declaration.type != 'declaration':
continue

0 comments on commit e00e393

Please sign in to comment.