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

Comments

Projects
None yet
2 participants
@Tontyna
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 label Jan 20, 2018

@liZe liZe added this to the 43 milestone Jan 20, 2018

@liZe liZe closed this in 9e59376 Jan 28, 2018

@liZe

This comment has been minimized.

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

This comment has been minimized.

Contributor

Tontyna commented Feb 2, 2018

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

@liZe

This comment has been minimized.

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