Skip to content

Commit 7459d19

Browse files
committed
Support hex colors with alpha channels
A deprecation for the old behaviour landed in #2302. This PR removes the deprecation warning for the old behaviour, and starts parsing 4 and 8 digit hex values as Colors. Looks like we had support for 8 digit hex colors for a while but somehow 4 digit support was missed. Spec sass/sass-spec#1273 Fixes #2674
1 parent 924cb48 commit 7459d19

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/parser.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,19 @@ namespace Sass {
15981598
1, // alpha channel
15991599
parsed);
16001600
}
1601+
else if (parsed.length() == 5) {
1602+
std::string r(2, parsed[1]);
1603+
std::string g(2, parsed[2]);
1604+
std::string b(2, parsed[3]);
1605+
std::string a(2, parsed[4]);
1606+
color = SASS_MEMORY_NEW(Color,
1607+
pstate,
1608+
static_cast<double>(strtol(r.c_str(), NULL, 16)),
1609+
static_cast<double>(strtol(g.c_str(), NULL, 16)),
1610+
static_cast<double>(strtol(b.c_str(), NULL, 16)),
1611+
static_cast<double>(strtol(a.c_str(), NULL, 16)) / 255,
1612+
parsed);
1613+
}
16011614
else if (parsed.length() == 7) {
16021615
std::string r(parsed.substr(1,2));
16031616
std::string g(parsed.substr(3,2));
@@ -1694,17 +1707,7 @@ namespace Sass {
16941707
{ return lexed_hex_color(lexed); }
16951708

16961709
if (lex< hexa >())
1697-
{
1698-
std::string s = lexed.to_string();
1699-
1700-
deprecated(
1701-
"The value \""+s+"\" is currently parsed as a string, but it will be parsed as a color in",
1702-
"future versions of Sass. Use \"unquote('"+s+"')\" to continue parsing it as a string.",
1703-
true, pstate
1704-
);
1705-
1706-
return SASS_MEMORY_NEW(String_Quoted, pstate, lexed);
1707-
}
1710+
{ return lexed_hex_color(lexed); }
17081711

17091712
if (lex< sequence < exactly <'#'>, identifier > >())
17101713
{ return SASS_MEMORY_NEW(String_Quoted, pstate, lexed); }

0 commit comments

Comments
 (0)