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

cssesc always escapes identifier characters above U+00A0 #8

Open
Jessidhia opened this issue Jul 6, 2016 · 4 comments
Open

cssesc always escapes identifier characters above U+00A0 #8

Jessidhia opened this issue Jul 6, 2016 · 4 comments

Comments

@Jessidhia
Copy link

As is not demonstrated by the online demo at https://mothereff.in/css-escapes.

If a @charset "utf-8"; directive is present in the input, or an appropriate option is set in the options object, it would be nice to be able to preserve characters that don't need to be escaped.

The CSS 2.1 spec allows identifiers to contain characters above U+00A0, and at least CSS 2.0 allowed characters "161 and higher".

@mathiasbynens
Copy link
Owner

This suggestion goes against the goal of this library:

A JavaScript library for escaping CSS strings and identifiers while generating the shortest possible ASCII-only output.

To only escape what’s absolutely necessary for modern browsers, you could use CSS.escape().

That said, cssesc could have an option to opt-in to similar behavior. If someone submits a patch, I’ll consider it.

@Jessidhia
Copy link
Author

Indeed, including high characters should be an off-by-default option if provided at all. As for css.escape, there is unfortunately no way to use it without it writing to global :(

@chriseppstein
Copy link
Contributor

I would like to have this option and will make a PR for it. The polyfil does not optimize string escapes, and I feel this library is a better place to have both capabilities so that a single dependency can accommodate libraries that need to handle a range of browser support preferences from users.

Do you have any preference for the option name (and corresponding CLI switch)? I suggest one of the following (in order of my most preferred to least preferred):

  • preserveUnicode (defaults to false)
  • onlySpecialChars (defaults to false)
  • unicodeOutput (defaults to false)
  • asciiOutput (defaults to true)

@mathiasbynens
Copy link
Owner

I'd prefer the name minimal, to match jsesc: https://github.com/mathiasbynens/jsesc#minimal

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

No branches or pull requests

3 participants