-
Notifications
You must be signed in to change notification settings - Fork 149
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
Add format option to convert all colors to 6 character hex codes #728
Comments
Hi @hosef, thanks for suggesting this! Do you have a link to the part of the reference that says that color values need to be six-digit hex codes? According to https://developer.mozilla.org/en-US/docs/Web/CSS/hex-color, there are multiple formats, ranging from 3- to 8-value formats. Also, I'm not sure normalizing the color format should be a responsibility of the CSS parser. IMHO, a parser should return the CSS as it is and not transform ist. (That's one of the reasons we're going to drop the shorthand notation expansion in #511.) @sabberworm @JakeQZ What do you think? |
It is from the HTML5 spec, not the CSS spec. I am not sure why, but HTML color inputs require exactly that format to use them. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#value |
Thanks! I wasn't aware of that. Still, I tend to think this is outside of the scope of parsing CSS, but should be done by the PHP that uses the parsed CSS. I'd like to hear the thoughts of the other project maintainers on this. |
I agree it’s outside the scope of parsing CSS. However, I don’t think it’s outside the scope of stringifying to CSS, which this library also does. As a matter of fact, I think |
It indeed has that option! https://github.com/MyIntervals/PHP-CSS-Parser/blob/main/src/OutputFormat.php#L27 @hosef Does this option solve your request? |
@oliverklee I did see that. It is better than not using it, but unfortunately it still doesn't work because it tries to convert the color into a 3 digit color code when that is an option. PHP-CSS-Parser/src/Value/Color.php Line 167 in f0a5876
|
Is the plan to move the code for manipulating the css into another project so this one will only parse the files? |
@hosef No, at the moment we have no plans in that direction. The only similar thing that was decided was deprecating and removing the expansion of shorthand properties. |
In the HTML 5 spec for color input elements, it says that values should always be a 6character hex code. If it does not match that format, then the browser will use #000000 as the default value for your fields.
It would be really handy to have the option to convert all of the colors to that format so that they can be used in forms without needing to do further processing of them.
The text was updated successfully, but these errors were encountered: