-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
Support all CSS color formats #12
Comments
I implemented most of the functions here. Do I make one PR for all or a PR for each commit ? |
One for all sounds great. Thank you very much. |
No problem! |
After the updates by @musikid, we do now support almost every possible color format in the CSS spec. While testing the examples given on the website mentioned above, I found two cases which were not supported yet:
Maybe we should try to solve these in a more general case (instead of adding even more regex patterns):
There were a few more cases which also did not work, but I don't think we have to necessarily support them (mostly involving alpha values). |
Hey, I'm interested in tackling the general parsing problem here. Do you think that using a parser combinator library (such as nom) would be a good solution here? |
fantastic 👍
That's what I was thinking about when writing "… instead of adding even more regex patterns" above 😄. I initially wondered if I should use a parser combinator library when writing the first few patterns, but I wasn't sure if it would definitely be the better solution. We certainly don't need all the power of a generic parser here. It's definitely manageable with a collection of regex patterns, but the code duplication isn't exactly great. In short, I'd be in favor of a parser-combinator solution if:
|
I started this last night, I got this far, using nom:
Which handles all the hex rgb cases, AFAICT. A lot simpler than 2-3 regexes, imo. Using nom also allows us to get error messages about the input, if that seems useful. |
See https://developer.mozilla.org/en-US/docs/Web/CSS/color_value for all details and test cases
#ff0000
)#f00
)rgb(0, 0, 255)
rgb(0%, 50%, 100%)
hsl(120, 100%, 75%)
hsl(…,…,…)
in all variations°
signrebeccapurple
)optional:
rgb(R G B[ A])
- only a draftgray(0.3)
gray(30%)
rad
instead of degreesturn
s instead of degreesThe text was updated successfully, but these errors were encountered: