Skip to content

Commit 9fe8a86

Browse files
committed
Added 8-digit hex color #132
1 parent 314805d commit 9fe8a86

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Released on tbd.
1111
- Fixed ordering of rows and columns in `grid` and `grid-gap` (#137)
1212
- Fixed inclusion of CSS from stylesheets (#140)
1313
- Added further compactification of CSS tuples (#89, #93)
14+
- Added support for 8-digit hex color codes (#132)
1415

1516
# 0.17.0
1617

src/AngleSharp.Css.Tests/Library/StringRepresentation.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ public void SimpleColorWorksWithHexOutput_Issue96()
4141
}
4242

4343
[Test]
44-
public void TransparentColorDoesNotWorkWithHexOutput_Issue96()
44+
public void TransparentColorWorksWithHexOutput_Issue132()
4545
{
4646
var color = new Color(65, 12, 48, 10);
4747
Color.UseHex = true;
4848
var text = color.CssText;
4949
Color.UseHex = false;
50-
Assert.AreEqual("rgba(65, 12, 48, 0.04)", text);
50+
Assert.AreEqual("#410C300A", text);
5151
}
5252

5353
[Test]

src/AngleSharp.Css/Values/Primitives/Color.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,16 @@ public String CssText
395395
{
396396
return CssKeywords.Invert;
397397
}
398-
else if (_alpha == 255 && UseHex)
398+
else if (UseHex)
399399
{
400-
return $"#{_red.ToString("X2", CultureInfo.InvariantCulture)}{_green.ToString("X2", CultureInfo.InvariantCulture)}{_blue.ToString("X2", CultureInfo.InvariantCulture)}";
400+
var color = $"#{_red.ToString("X2", CultureInfo.InvariantCulture)}{_green.ToString("X2", CultureInfo.InvariantCulture)}{_blue.ToString("X2", CultureInfo.InvariantCulture)}";
401+
402+
if (_alpha != 255)
403+
{
404+
return $"{color}{_alpha.ToString("X2", CultureInfo.InvariantCulture)}";
405+
}
406+
407+
return color;
401408
}
402409
else
403410
{

0 commit comments

Comments
 (0)