Skip to content

Commit 91a7444

Browse files
committed
Improved serialization of shadows #97
1 parent 35e0903 commit 91a7444

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

src/AngleSharp.Css.Tests/Declarations/CssProperty.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public void CssBoxShadowNormalSpreadBlackLegal()
335335
Assert.IsFalse(property.IsImportant);
336336
Assert.IsFalse(property.IsInherited);
337337
Assert.IsTrue(property.HasValue);
338-
Assert.AreEqual("10px 5px 5px", property.Value);
338+
Assert.AreEqual("10px 5px 5px rgba(0, 0, 0, 1)", property.Value);
339339
}
340340

341341
[Test]
@@ -407,7 +407,7 @@ public void CssBoxShadowOffsetColorLegal()
407407
Assert.IsFalse(property.IsImportant);
408408
Assert.IsFalse(property.IsInherited);
409409
Assert.IsTrue(property.HasValue);
410-
Assert.AreEqual("5px 4px", property.Value);
410+
Assert.AreEqual("5px 4px rgba(0, 0, 0, 1)", property.Value);
411411
}
412412

413413
[Test]
@@ -419,7 +419,7 @@ public void CssBoxShadowOffsetBlurColorLegal()
419419
Assert.IsFalse(property.IsImportant);
420420
Assert.IsFalse(property.IsInherited);
421421
Assert.IsTrue(property.HasValue);
422-
Assert.AreEqual("5px 4px 2px", property.Value);
422+
Assert.AreEqual("5px 4px 2px rgba(0, 0, 0, 1)", property.Value);
423423
}
424424

425425
[Test]

src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public void CssTextShadowLegalInsetAtLast()
6565
Assert.IsTrue(property.HasValue);
6666
Assert.IsFalse(property.IsImportant);
6767
Assert.IsFalse(property.IsInherited);
68-
Assert.AreEqual("inset 0 0 2px", property.Value);
68+
Assert.AreEqual("inset 0 0 2px rgba(0, 0, 0, 1)", property.Value);
6969
}
7070

7171
[Test]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace AngleSharp.Css.Tests.Declarations
2+
{
3+
using AngleSharp.Css.Dom;
4+
using AngleSharp.Css.Parser;
5+
using AngleSharp.Html.Parser;
6+
using NUnit.Framework;
7+
8+
[TestFixture]
9+
public class CssTextShadowProperty
10+
{
11+
[Test]
12+
public void ColorNotIncluded_Issue97()
13+
{
14+
var html = @"<div style=""text-shadow: 2px 2px 2px #000"">test</div>";
15+
var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
16+
var dom = parser.ParseDocument(html);
17+
var div = dom.QuerySelector("div");
18+
var style = div.GetStyle();
19+
var css = style.CssText;
20+
Assert.AreEqual("text-shadow: 2px 2px 2px rgba(0, 0, 0, 1)", css);
21+
}
22+
}
23+
}

src/AngleSharp.Css/Parser/Micro/ShadowParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static CssShadowValue ParseShadow(this StringSource source)
6767
offsetY,
6868
blurRadius,
6969
spreadRadius,
70-
color ?? Color.Black);
70+
color);
7171
}
7272

7373
source.BackTo(start);

src/AngleSharp.Css/Values/Composites/CssShadowValue.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ sealed class CssShadowValue : ICssCompositeValue
1616
private readonly ICssValue _offsetY;
1717
private readonly ICssValue _blurRadius;
1818
private readonly ICssValue _spreadRadius;
19-
private readonly Color _color;
19+
private readonly Color? _color;
2020

2121
#endregion
2222

@@ -31,7 +31,7 @@ sealed class CssShadowValue : ICssCompositeValue
3131
/// <param name="blurRadius">The blur radius of the shadow.</param>
3232
/// <param name="spreadRadius">The spread radius of the shadow.</param>
3333
/// <param name="color">The color of the shadow.</param>
34-
public CssShadowValue(Boolean inset, ICssValue offsetX, ICssValue offsetY, ICssValue blurRadius, ICssValue spreadRadius, Color color)
34+
public CssShadowValue(Boolean inset, ICssValue offsetX, ICssValue offsetY, ICssValue blurRadius, ICssValue spreadRadius, Color? color)
3535
{
3636
_inset = inset;
3737
_offsetX = offsetX;
@@ -72,9 +72,9 @@ public String CssText
7272
parts.Add(_spreadRadius.CssText);
7373
}
7474

75-
if (_color != Color.Black)
75+
if (_color.HasValue)
7676
{
77-
parts.Add(_color.CssText);
77+
parts.Add(_color.Value.CssText);
7878
}
7979

8080
return String.Join(" ", parts);
@@ -84,7 +84,7 @@ public String CssText
8484
/// <summary>
8585
/// Gets the color of the shadow.
8686
/// </summary>
87-
public Color Color => _color;
87+
public Color Color => _color ?? Color.Black;
8888

8989
/// <summary>
9090
/// Gets the horizontal offset.

0 commit comments

Comments
 (0)