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
Milestone

Comments

@Tontyna
Copy link
Contributor

@Tontyna 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
Copy link
Member

@liZe 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 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 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants