[Whatwg] [whatwg] Color attributes

Simon Pieters zcorpan at gmail.com
Fri Jul 27 04:07:26 PDT 2007


On Thu, 05 Jul 2007 23:43:55 +0200, Simon Pieters <zcorpan at gmail.com>  
wrote:

> Color attributes in HTML have special processing.
>
> Some tests/demos:
>
>      http://simon.html5.org/test/html/parsing/color-attributes/
>
> https://bugzilla.mozilla.org/attachment.cgi?id=188040 contains further
> tests and an algorithm that is supposed to match what IE does. The only
> flaw in that algorithm AFAICT is that there is a step missing before the
> first step: match the value against the list of supported color keywords.
>
> For reference, the complete algorithm would be:
>
>     1. If the value case-insensitively matches a color keyword, use that  
> and
>        abort these steps. [CSS3COLOR]

"transparent" is also to be treated as a keyword, meaning transparent. (It  
seems that IE treats transparent as black for text color, but that's a CSS  
thing.)

>     2. Trim all but the first 128 chars from the string.
>     3. If it exists, strip the first leading #.
>     4. Replace non-valid-hex chars with 0s.
>     5. Lower-case the string.
>     6. Make string length a multiple of 3 and a minimum of 3 by  
> appending 0s.
>     7. Split the string into 3 equal segments.
>     8. Trim all but the right-most 8 chars from each segment.
>     9. If segment length is 1, left-pad each segment with a 0, else:
>    10. While segment length is greater than 2 and the first char of each
>        segment is equal to 0, trim the left-most char from each segment,
>        then:
>    11. Trim all but the first 2 chars from each segment.
>    12. Join the segments and append them to a # char to create the final
>        string.
>
> [...]

-- 
Simon Pieters



More information about the whatwg mailing list