Skip to content

Strip @charset CSS at-rules #1515

@westonruter

Description

@westonruter

Themes sometimes include a @charset at-rule. For example, in the Twenty Nineteen theme under development it is getting added by the SASS generator:

https://github.com/WordPress/twentynineteen/blob/01423c688c684ee4faee3d496a128e6f389ea614/style.css#L1

This rule is not valid in AMP because styles must be in the style[amp-custom] element and per MDN, @charset

cannot be used inside a style attribute on an HTML element or inside the <style> element where the character set of the HTML page is relevant.

Since AMP requires UTF-8, all documents are going to be using this character encoding. When a document doesn't, we'll need to convert it (#855). The meta[charset] will be indicating the encoding, and the @charset is irrelevant and illegal.

We need to check how PHP-CSS-Parser is handling character encodings, if it is reading the @charset to determine the encoding and the internal encoding it uses. Bottom line is that we need the externally-fetched stylesheet to end up as UTF-8, and we need to drop the @charset.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions