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

Add support for escaping names in CSS #1049

Closed
koaning opened this issue Oct 28, 2022 · 5 comments
Closed

Add support for escaping names in CSS #1049

koaning opened this issue Oct 28, 2022 · 5 comments
Labels
enhancement New feature or request

Comments

@koaning
Copy link

koaning commented Oct 28, 2022

I'm working on a plugin that tries to mimic tailwind.css for Textual. It's called tuilwindcss.

Many things work swell out of the box, but I'm stuck on the relative widths. In tailwind.css you're able to use a class like w-1/5 to declare a 20% width.

That would lead me to add the following classes to my generated CSS file.

w-1/5 {
    width: 20%;
}

w-1/4 {
    width: 25%;
}

w-1/3 {
    width: 33.333%;
}

But! When added that to my CSS file, I got this error when I tried actually using it.

> python docs/examples/css.py
 Error in stylesheet:
 /home/vincent/Development/tuilwindcss/docs/examples/tuilwind.css:79074:2
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│   79072text-style: strike;                                                                   │
│   79073 }                                                                                         │
│ ❱ 79074                                                                                           │
│   79075 w-1\5 {                                                                                  │
│   79076width: 20%;                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
 • Expected one of 'combinator child', 'comment start', 'declaration set start', 'new selector',     
 'pseudo class', 'selector', 'selector class', 'selector id', 'selector universal', or 'whitespace'. 
 • Did you forget a semicolon at the end of a line?  

I think Tailwind "solves" this by adding an escape character so that w-1/5 becomes w-1/\5, but that yields nearly the same error.

python docs/examples/css.py
 Error in stylesheet:
 /home/vincent/Development/tuilwindcss/docs/examples/tuilwind.css:79074:2
╭───────────────────────────────────────────────────────────────────────────────────────────────────╮
│   79072 │   text-style: strike;                                                                   │
│   79073 }                                                                                         │
│ ❱ 79074                                                                                           │
│   79075 w-1\/5 {                                                                                  │
│   79076 │   width: 20%;                                                                           │
╰───────────────────────────────────────────────────────────────────────────────────────────────────╯
 • Expected one of 'combinator child', 'comment start', 'declaration set start', 'new selector',     
 'pseudo class', 'selector', 'selector class', 'selector id', 'selector universal', or 'whitespace'. 
 • Did you forget a semicolon at the end of a line?  

Is this something you'd like to support? It would be fun on my end to see how far I might be able to get tuilwind to really work like tailwind.

@koaning koaning changed the title CSS class names. CSS class names with / Oct 28, 2022
@willmcgugan
Copy link
Collaborator

TBH I didn't even know the CSS has this escaping behaviour. I think we should support it in general, which would enable this use-case amongst others.

@willmcgugan willmcgugan changed the title CSS class names with / Add support for escaping names in CSS Oct 29, 2022
@koaning
Copy link
Author

koaning commented Oct 30, 2022

TBH I didn't even know the CSS has this escaping behavior.

Yeah, it's definitely something I only learned because of the tuilwindcss project 😅 . Might be good to double-check the spec on it, though. Now that I think of it; it's merely something that I've spotted while hacking around and checking the tailwind files. It could be that CSS has some specific rules.

@davep davep added the enhancement New feature or request label Jan 11, 2023
@UmBsublime
Copy link

If I understand the spec correctly, escaping with \ appears to be documented here for CSS2
https://www.w3.org/TR/CSS21/syndata.html#characters

In CSS, identifiers (including element names, classes, and IDs in selectors) can contain only the characters [a-zA-Z0-9] and ISO 10646 characters U+00A0 and higher, plus the hyphen (-) and the underscore (_); they cannot start with a digit, two hyphens, or a hyphen followed by a digit. Identifiers can also contain escaped characters and any ISO 10646 character as a numeric code (see next item). For instance, the identifier "B&W?" may be written as B\&W\? or B\26 W\3F.

And the CSS3 spec seems to point to that same section: https://www.w3.org/TR/selectors-3/#selector-syntax

Characters in Selectors can be escaped with a backslash according to the same escaping rules as CSS. [CSS21].

@willmcgugan
Copy link
Collaborator

Going to close this one for now. It's not a bad idea, and we may end up implementing it, but it seems niche for now. Will reconsider if there is a demand.

Copy link

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

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

No branches or pull requests

4 participants