Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Support hex colors with alpha channels
Browse files Browse the repository at this point in the history
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
  • Loading branch information
xzyfer committed Jul 26, 2018
1 parent 0fa69a5 commit fbdcc37
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1598,6 +1598,19 @@ namespace Sass {
1, // alpha channel
parsed);
}
else if (parsed.length() == 5) {
std::string r(2, parsed[1]);
std::string g(2, parsed[2]);
std::string b(2, parsed[3]);
std::string a(2, parsed[4]);
color = SASS_MEMORY_NEW(Color,
pstate,
static_cast<double>(strtol(r.c_str(), NULL, 16)),
static_cast<double>(strtol(g.c_str(), NULL, 16)),
static_cast<double>(strtol(b.c_str(), NULL, 16)),
static_cast<double>(strtol(a.c_str(), NULL, 16)) / 255,
parsed);
}
else if (parsed.length() == 7) {
std::string r(parsed.substr(1,2));
std::string g(parsed.substr(3,2));
Expand Down Expand Up @@ -1694,17 +1707,7 @@ namespace Sass {
{ return lexed_hex_color(lexed); }

if (lex< hexa >())
{
std::string s = lexed.to_string();

deprecated(
"The value \""+s+"\" is currently parsed as a string, but it will be parsed as a color in",
"future versions of Sass. Use \"unquote('"+s+"')\" to continue parsing it as a string.",
true, pstate
);

return SASS_MEMORY_NEW(String_Quoted, pstate, lexed);
}
{ return lexed_hex_color(lexed); }

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

0 comments on commit fbdcc37

Please sign in to comment.