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

Parse escaped content as part of all literals and values #36

Open
kitten opened this issue Nov 30, 2017 · 0 comments
Open

Parse escaped content as part of all literals and values #36

kitten opened this issue Nov 30, 2017 · 0 comments

Comments

@kitten
Copy link

kitten commented Nov 30, 2017

In CSS any literal or value can contain escaped content, a simple example being content: "\""; Here we escape another quote inside the string with a backslash.

The best article on what's possible is here: https://mathiasbynens.be/notes/css-escapes

But the tl;dr is, any character can be escaped either using itself: "\+" = "+" or using a hex code: "\2b " = "+" or "\00002b" = "+". Note that if the hex escape sequence has an ambiguous length (anything else than exactly 6 hex chars) then a space must follow it.

A simpler detection of escaped content would be to allow either one char, or one or more hex chars (/[a-f][0-9]/i) with an optional space after them. This is easier and more efficient to parse. (Used by PostCSS as a heuristic for instance)

As soon as a character is escaped it can become part of a literal or a value, but it can never be part of any other token, meaning that in #\#some-id { the hash symbol doesn't stand for CSS’ hash token.

A problem for bredon in particular is that since any literal's char can be escaped, that also means that for 100% those would need to be normalised for literals. A simple example is font-\size which is still detected as font-size in the browser. So for correct detection and to make plugins work correctly this technically needs to be normalised. (This normalisation is not done in most CSS parsers however)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants