-
Notifications
You must be signed in to change notification settings - Fork 657
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
[css-syntax] Trim whitespace around declarations? #774
Comments
+1 |
agenda+ for a yay/nay on this. I don't have a strong opinion either way. |
How would this affect declarations of the form: :root { --my-var: ; }
.class { --my-var: } …which currently is a valid CSS var consisting of a single whitespace token? Is it fine so long as the The ability to create empty vars is useful when you are adding a variable to a list property: background-image: var(--element-bg) linear-gradient(black, gray);
transform: var(--base-transform) rotate(45deg); |
Those two are exactly equivalent - in the second, the declaration extends until it hits the (There shouldn't be any difference between I'm not intending to make "empty vars" invalid, just to trim the representation of variables. Under this proposal, both of those would report the property's value as an empty string. |
Strong +1 for this. It's very much against author expectations that CSSOM methods return whitespace around a value and it means that |
The CSS Working Group just discussed
The full IRC log of that discussion<astearns> topic: [css-syntax] Trim whitespace around declarations?<astearns> github topic: [css-syntax] Trim whitespace around declarations? <astearns> github topic: https://github.com//issues/774 <fantasai> TabAtkins: This has impact on what custom property values are <fantasai> TabAtkins: Because custom properties capture tokens <fantasai> TabAtkins: Currently the white space before first value token is preserved <fantasai> TabAtkins: All of the normal properties serialize out from OM, so they get normalized white space output <fantasai> TabAtkins: Some people brought up maybe we should trim the white space from beginning and end of a token stream <fantasai> TabAtkins: This would be a tweak to the Syntax spec <fantasai> TabAtkins: to throw away this white space <fantasai> TabAtkins: No consequence for ordinary CSS, they will continue to parse and serialize as usual <fantasai> TabAtkins: It may or may not have an observable difference on serializing a rule of a style sheet... I think they generally reserialize from internal structures <gregwhitworth> basically this saves authors from writing trim() when manipulating custom props <fantasai> TabAtkins: Would have desired difference on serialization of custom property value when ppl write with typical whitespace after colon <fantasai> TabAtkins: Saves authors from writing trim(), right, and also from forgetting to write trim() because they never have to write that for any other property <fantasai> leaverou: Is there any use case where you want the white space <fantasai> TabAtkins: If you're embedding an esoteric language... <fantasai> TabAtkins: If you're embedding another programming language into CSS you'll have consequences anyway <fantasai> TabAtkins: Don't think any other issue <fantasai> leaverou: So benefit to it, and not hurting any use case. So I'm hugely in favor. <fantasai> leaverou: Every time I use OM for custom properties, have to use trim(), it's really annoying. <ChrisL> +1 to trimming <fantasai> astearns: Proposal to trim whitespace on either side of all declarations. In favor / opposed? <fantasai> RESOLVED: trim white space before / after property value in a declaration. |
If we do this, we should also tweak CSSOM spec to add the whitespaces back during serialization. |
That's already there, no? https://drafts.csswg.org/cssom/#serialize-a-css-declaration (This change actually makes the CSSOM round-trip values properly, instead of adding a space to the front.) |
@tabatkins the |
The note at https://drafts.csswg.org/css-variables-1/#syntax
needs updating either way. |
…only whitespace, as that whitespace is now trimmed away, per Syntax. Relates to #774.
…declaration-value>> optional so you can still have an empty var. Relates to #774.
Note that the change to the custom var grammar means that So allowing substituting an empty sequence of tokens requires change to those rules [or perhaps change to the initial value]. Another consideration is that However, do we absolutely need to allow custom vars to have an empty value? 'background-image' should be doable using a none layer, and 'transform' can of course be done with an identity transform. It's certainly believable that uses exist; I'm just saying that reverting adding the ‘?’ to custom var grammar is an easy option for now, and might be taken if no-one can for now think of a convincing use. |
Why would it make it have its initial value? "Empty" is not the initial value (but the initial value does, unfortunately, serialize as empty). |
As per w3c/csswg-drafts#881 and w3c/csswg-drafts#774. Differential Revision: https://phabricator.services.mozilla.com/D116459 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1713787 gecko-commit: d55d07d3e8ccfa9a6bd619e5a1863927e45d3aae gecko-reviewers: xidorn
As per w3c/csswg-drafts#881 and w3c/csswg-drafts#774. Differential Revision: https://phabricator.services.mozilla.com/D116459 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1713787 gecko-commit: d55d07d3e8ccfa9a6bd619e5a1863927e45d3aae gecko-reviewers: xidorn
The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes gh-4926 Closes gh-4930
The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes jquerygh-4926 Closes jquerygh-4930 (partially cherry picked from efadfe9)
The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes jquerygh-4926 Closes jquerygh-4930 Closes jquerygh-4936 (partially cherry picked from efadfe9)
The spec has recently changed and CSS Custom Properties values are trimmed now. This change makes jQuery polyfill that new behavior for all browsers. Ref w3c/csswg-drafts#774 Fixes gh-4926 Closes gh-4930 (partially cherry picked from commit efadfe9)
There was a spec change a few years ago requiring spaces around CSS declaration's value to be trimmed: w3c/csswg-drafts#1986. The discussion leading to this spec change: w3c/csswg-drafts#774. This closes issue web-platform-tests#34880.
There was a spec change a few years ago requiring spaces around CSS declaration's value to be trimmed: w3c/csswg-drafts#1986. The discussion leading to this spec change: w3c/csswg-drafts#774. This closes issue #34880.
…ing values, a=testonly Automatic update from web-platform-tests CSS variables tests should require trimming values (#37239) There was a spec change a few years ago requiring spaces around CSS declaration's value to be trimmed: w3c/csswg-drafts#1986. The discussion leading to this spec change: w3c/csswg-drafts#774. This closes issue #34880. -- wpt-commits: c96c37fa465273e3e87bdaa79b157884417129b7 wpt-pr: 37239
…ing values, a=testonly Automatic update from web-platform-tests CSS variables tests should require trimming values (#37239) There was a spec change a few years ago requiring spaces around CSS declaration's value to be trimmed: w3c/csswg-drafts#1986. The discussion leading to this spec change: w3c/csswg-drafts#774. This closes issue #34880. -- wpt-commits: c96c37fa465273e3e87bdaa79b157884417129b7 wpt-pr: 37239
As per w3c/csswg-drafts#881 and w3c/csswg-drafts#774. Differential Revision: https://phabricator.services.mozilla.com/D116459
As per w3c/csswg-drafts#881 and w3c/csswg-drafts#774. Differential Revision: https://phabricator.services.mozilla.com/D116459
As per w3c/csswg-drafts#881 and w3c/csswg-drafts#774. Differential Revision: https://phabricator.services.mozilla.com/D116459
Right now, the Syntax spec is clear about what the value of a declaration is - it's all the tokens between the : and the ;. In particular, this includes any initial or final whitespace, which is pretty common in declarations like
color: red;
or in omitted-semicolon situations like:When serializing non-custom properties, this whitespace doesn't matter; the property value has been parsed into a specialized data structure, and serialization just works off of that - it doesn't even attempt to preserve source whitespace. This means, for example, that you can be sure the first character of 'color' will be a non-whitespace char.
But the value of a custom property is the token list it parses as, so technically the initial/final whitespace is part of its value and should be serialized with it. Add to this the resolution at TPAC that custom properties should store their source representations so they can reserialize exactly as written (rather than, in some situations, serializing with extra comments inserted). On the other hand, this can result in unexpected whitespace in the serialization, as the initial/final whitespace isn't really considered to be "part of the value". (This is why I'm reporting it - one of the engineers on our team was writing some code with custom properties and got tripped up by this.)
So my question is: do we want to alter the "consume a declaration" algorithm to trim initial/final whitespace tokens? That dodges the resolution, as it won't be part of the value anymore. This will have zero effect on ordinary properties, just custom properties, and will likely bring custom property serialization slightly more in line with author expectations.
The text was updated successfully, but these errors were encountered: