Skip to content

[css-syntax] Tokenizing hex colors following spec is ambiguous #6204

@tbjgolden

Description

@tbjgolden

I have been attempting to write a CSS tokenizer following the steps listed here:

https://drafts.csswg.org/css-syntax-3/#consume-token

However, it seems that there's no way (that I can see) to tokenize a hex color according to the steps listed.

When reaching U+0023 NUMBER SIGN (#), it contains instructions to create a hash token, but the instructions do not include a way to tokenize a hex color into a series of tokens that could be reasonably interpreted as a color.

example 1: #1e2125 <delim-token #><number-token 1*10^2125> (which ends up being "rounded to Infinity")
example 2: #ee2125 <hash-token #ee2125>
example 3: #1a2125 <delim-token #><number-token 1><ident-token a2125>

I could not find anything in document that covers this.


link to my test case: https://github.com/tbjgolden/media-query-parser/blob/main/src/parse/lexicalAnalysis.test.ts#L183-L245

Metadata

Metadata

Assignees

No one assigned

    Labels

    Closed as Question AnsweredUsed when the issue is more of a question than a problem, and it's been answered.css-syntax-3

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions