This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 26208 - For parsing CSS <color> values, this should explicitly ref the CSS Syntax spec, and use the "parse a component value" algorithm defined there.
Summary: For parsing CSS <color> values, this should explicitly ref the CSS Syntax spe...
Status: RESOLVED FIXED
Alias: None
Product: WHATWG
Classification: Unclassified
Component: HTML (show other bugs)
Version: unspecified
Hardware: Other other
: P3 normal
Target Milestone: Unsorted
Assignee: Ian 'Hixie' Hickson
QA Contact: contributor
URL: http://www.whatwg.org/specs/web-apps/...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-06-26 20:45 UTC by contributor
Modified: 2014-09-22 16:26 UTC (History)
3 users (show)

See Also:


Attachments

Description contributor 2014-06-26 20:45:17 UTC
Specification: http://www.whatwg.org/specs/web-apps/current-work/multipage/infrastructure.html
Multipage: http://www.whatwg.org/C#dependencies
Complete: http://www.whatwg.org/c#dependencies
Referrer: http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html

Comment:
For parsing CSS <color> values, this should explicitly ref the CSS Syntax
spec, and use the "parse a component value" algorithm defined there.

Posted from: 2620:0:1000:1b01:a2b3:ccff:fefb:42ac
User agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.32 Safari/537.36
Comment 1 Tab Atkins Jr. 2014-06-26 20:46:35 UTC
See, for example, https://github.com/whatwg/meta-brand-color#finding-the-brand-color:

> For each element in candidate elements:
>   1. Parse a component value from element's content attribute value. [[css-syntax]]
>   2. Attempt to parse the result as a CSS color. If it succeeds, return the parsed color.
Comment 2 Ian 'Hixie' Hickson 2014-06-30 23:44:29 UTC
Why does this have to be two steps instead of one? I'm not sure I follow. I'll look into it more closely.
Comment 3 Tab Atkins Jr. 2014-07-01 02:08:52 UTC
You could combine them, but it's still essentially two steps - one to turn codepoints into some structure of CSS tokens, then another to run a grammar against those tokens.

This matters, for example, due to whitespace - if you just check if an attribute's value parses as a CSS color, it'll fail due to whitespace if there's any at the beginning/end.  If you first get a component value, that discards whitespace at the beginning/end.  Right now you explicitly discard the whitespace, but that's not necessary if you ref Syntax properly.
Comment 4 Ian 'Hixie' Hickson 2014-09-03 22:49:02 UTC
Well I just mean that in most other cases, the tokenisation and parsing stages are wrapped into a single call site. For example, if you want to parse HTML, you just run the HTML parser, you don't have to manage the handoff of tokens from the tokeniser to the tree builder.

Presumably, the output of "parse a component value", and thus the input of "parse the result as a CSS color", is not a string, but a sequence of tokens or some such. In which case, "parse the element's content attribute value as a CSS color" should be meaningless (a type mismatch error).

So what I would suggest, is that we define "parse [a string] as [some CSS value]" as doing the tokenisation and any other processing that it needs, so that I can then say "parse [a string] as a CSS <color> value" and it does the right thing. Seems like that would make other specs integrating with CSS less verbose and more maintainable in the face of changes on the CSS side. The fact that there's a separate tokenisation step seems like an implementation detail of the CSS syntax specifications.

Anyway, if you disagree, just let me know, happy to do it however you want.
Comment 5 Tab Atkins Jr. 2014-09-04 02:26:00 UTC
Yeah, I'm fine with adding a hook like "parse as [[css grammar thing]]", which, like the other parsing functions, accepts either a list of codepoints, a list of tokens, or a list of component values.  It would do a "parse a list of component values" first, then attempt to match it against the specified grammar.
Comment 6 Ian 'Hixie' Hickson 2014-09-04 18:38:15 UTC
Cool. I'll update HTML to use that wording and link to the relevant part of CSS Syntax. Thanks!
Comment 7 Tab Atkins Jr. 2014-09-05 21:57:11 UTC
Here you go: http://dev.w3.org/csswg/css-syntax/#parse-grammar
Comment 8 Ian 'Hixie' Hickson 2014-09-19 19:21:20 UTC
Please take a look at the HTML prose and see if it's ok. In particular, note the problem with the 'font' property, not sure how to handle that, and check the example that starts "For example, user agents are required to close all open constructs..." and make sure that that matches reality on your end. Thanks!
Comment 9 contributor 2014-09-19 19:21:32 UTC
Checked in as WHATWG revision r8793.
Check-in comment: Better reference CSS for parsing according to CSS.
https://html5.org/tools/web-apps-tracker?from=8792&to=8793
Comment 10 Tab Atkins Jr. 2014-09-19 21:28:50 UTC
(In reply to contributor from comment #9)
> Checked in as WHATWG revision r8793.
> Check-in comment: Better reference CSS for parsing according to CSS.
> https://html5.org/tools/web-apps-tracker?from=8792&to=8793

Per IRC discussion, the <'font'> nonterminal is what you want. It means "the grammar of the 'font' property", and excludes the global keywords.