So I’m using an IE specific filter that requires the colours to be in the long form of 6 characters. But I have a thousand line stylesheet filled with calls to my function using the short form of 3 characters. So I’m hoping that it’s possible to convert from the short to the long form from within the function. Any built-in or custom function will do. My function looks something like this:
td_gradient(color1, color2)
background-color (color1 + (color2 - color1) / 2)
background -webkit-gradient(linear, 0% 0%, 0% 100%, from(color1), to(color2))
background -webkit-linear-gradient(top, color1, color2)
background -moz-linear-gradient(top, color1, color2)
background -ms-linear-gradient(top, color1, color2)
background -o-linear-gradient(top, color1, color2)
filter s("progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorstr='%s', EndColorstr='%s')", color1, color2)
The input colours look like #333 and #123, but the Microsoft filter function requires #333333 and #112233. Is there any way to satisfy it without editing every instance or a colour in my stylesheet?
Looking at the stylus source code, in lib/nodes/rgba.js, there’s this method: RGBA.prototype.toString. On line 268, we find:
I experimented with building a function for you, but I can’t seem to get the color back as a string, to do string manipulation. So the easiest way for you would probably be to patch
RGBA.prototypeand remove this shortening.UPDATE: Ok, here is a function for you:
If you put it in a file
color.js, you can use it withstylus -u ./color.js, or stylus’ javascript API withuse. Stylus usage: