Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Named pages with pseudo-class #562

Closed
Tontyna opened this issue Jan 19, 2018 · 3 comments
Closed

Named pages with pseudo-class #562

Tontyna opened this issue Jan 19, 2018 · 3 comments
Labels
bug Existing features not working as expected
Milestone

Comments

@Tontyna
Copy link
Contributor

Tontyna commented Jan 19, 2018

css for named page with pseudo-class, e.g. @page mypage:left throws error Unsupported @page selector.

To prevent this and make pseudo-class work I altered the function preprocess_stylesheet() in weasyprint/css/__init__.py. Inserted the following code at line 680:

# 19.1.2017: implement named page with pseudo-class
# @page <name>:<left|right|blank|first>
elif (len(tokens) == 3 and
        tokens[0].type == 'ident' and
        tokens[1].type == 'literal' and
        tokens[1].value == ':' and
        tokens[2].type == 'ident'):
    pseudo_class = tokens[2].lower_value
    if pseudo_class in ('left', 'right'):
        types['side'] = pseudo_class
        specificity = (0, 0, 1)
    elif pseudo_class in ('blank', 'first'):
        types[pseudo_class] = True
        specificity = (0, 1, 0)
    else:
        LOGGER.warning('Unknown @page pseudo-class "%s", '
                       'the whole @page rule was ignored '
                       'at %s:%s.',
                       pseudo_class,
                       rule.source_line, rule.source_column)
        continue
    # page-name
    types['name'] = tokens[0].value
@liZe liZe added the bug Existing features not working as expected label Jan 20, 2018
@liZe liZe added this to the 43 milestone Jan 20, 2018
@liZe liZe closed this as completed in 9e59376 Jan 28, 2018
@liZe
Copy link
Member

liZe commented Jan 28, 2018

Thanks for the report, it should be fixed now (with support of comma-separated multiple page selectors, as defined in https://drafts.csswg.org/css-page-3/#syntax-page-selector). Tests are welcome!

liZe added a commit that referenced this issue Jan 30, 2018
@Tontyna
Copy link
Contributor Author

Tontyna commented Feb 2, 2018

Did some tests, works like a charm.
Even combined page pseudo-styles @page :blank:left { ... } are applied correctly.

@liZe
Copy link
Member

liZe commented Feb 2, 2018

Did some tests, works like a charm.
Even combined page pseudo-styles @page :blank:left { ... } are applied correctly.

Cool! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Existing features not working as expected
Projects
None yet
Development

No branches or pull requests

2 participants