Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
HtmlColor validator #504
I also have got a couple of questions regarding this issue:
This is what I've come up with:
Should we support RGB/RGBA as stings? Something else I'm missing?
all those cases look good a few more we should probably accept:
It looks like you can also definite colours using
The other case is how does the parsed value
I think best that we return an instance of
Another question: should we always validate to the same thing or leave the output format as it came in? Eg. if someone enters
Genuinely not sure what's best here. I think we have to have:
Turns out this is much more complicated than I thought, but quite fun :-)
By the way, it seems that defining
Another thing that I've just realised is that if we do all these fancy conversions, we have to take care of alpha composition. We cannot just drop alpha from
I would certainly expect the output format match the input's one. I think a user can add conversion to the needed format at a post validation step.
May be also splitted as
Return a lower cased name of the colour passed
This brings us to the first question I've asked: if we only validate that a colour passed is in the set of predefined colours defined in CSS3/SVG specification? Or we just try to validate a colour returning it's predifined name if we can find it, otherwise we fall back to
I woud go for an alias of
Yes, we're checking it's in the list of predefined colours from css3.
We don't want to do any clever stuff with the alpha channel, if it's there (and not 1.0/255) the colour has to be defined as
We can happily ignore
Let's just call it
For clarity I think
class Color: __slots__ = '_rgba', '_original', '_color_match' def __init__(...): self._rgba: Tuple[int, int, int, Optional[int]] = ... self._original: str = ... self._color_match: Union[str, None, bool] = None # used to cache the named color or that there is none
Obviously do it how you think best, but I think the above makes sense as a starting point.