Skip to content

Commit

Permalink
Improved serialization of shadows AngleSharp#97
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianRappl committed Jan 5, 2022
1 parent 35e0903 commit 91a7444
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/AngleSharp.Css.Tests/Declarations/CssProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ public void CssBoxShadowNormalSpreadBlackLegal()
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("10px 5px 5px", property.Value);
Assert.AreEqual("10px 5px 5px rgba(0, 0, 0, 1)", property.Value);
}

[Test]
Expand Down Expand Up @@ -407,7 +407,7 @@ public void CssBoxShadowOffsetColorLegal()
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("5px 4px", property.Value);
Assert.AreEqual("5px 4px rgba(0, 0, 0, 1)", property.Value);
}

[Test]
Expand All @@ -419,7 +419,7 @@ public void CssBoxShadowOffsetBlurColorLegal()
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("5px 4px 2px", property.Value);
Assert.AreEqual("5px 4px 2px rgba(0, 0, 0, 1)", property.Value);
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion src/AngleSharp.Css.Tests/Declarations/CssTextProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void CssTextShadowLegalInsetAtLast()
Assert.IsTrue(property.HasValue);
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.AreEqual("inset 0 0 2px", property.Value);
Assert.AreEqual("inset 0 0 2px rgba(0, 0, 0, 1)", property.Value);
}

[Test]
Expand Down
23 changes: 23 additions & 0 deletions src/AngleSharp.Css.Tests/Declarations/CssTextShadowProperty.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace AngleSharp.Css.Tests.Declarations
{
using AngleSharp.Css.Dom;
using AngleSharp.Css.Parser;
using AngleSharp.Html.Parser;
using NUnit.Framework;

[TestFixture]
public class CssTextShadowProperty
{
[Test]
public void ColorNotIncluded_Issue97()
{
var html = @"<div style=""text-shadow: 2px 2px 2px #000"">test</div>";
var parser = new HtmlParser(new HtmlParserOptions(), BrowsingContext.New(Configuration.Default.WithCss(new CssParserOptions())));
var dom = parser.ParseDocument(html);
var div = dom.QuerySelector("div");
var style = div.GetStyle();
var css = style.CssText;
Assert.AreEqual("text-shadow: 2px 2px 2px rgba(0, 0, 0, 1)", css);
}
}
}
2 changes: 1 addition & 1 deletion src/AngleSharp.Css/Parser/Micro/ShadowParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static CssShadowValue ParseShadow(this StringSource source)
offsetY,
blurRadius,
spreadRadius,
color ?? Color.Black);
color);
}

source.BackTo(start);
Expand Down
10 changes: 5 additions & 5 deletions src/AngleSharp.Css/Values/Composites/CssShadowValue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ sealed class CssShadowValue : ICssCompositeValue
private readonly ICssValue _offsetY;
private readonly ICssValue _blurRadius;
private readonly ICssValue _spreadRadius;
private readonly Color _color;
private readonly Color? _color;

#endregion

Expand All @@ -31,7 +31,7 @@ sealed class CssShadowValue : ICssCompositeValue
/// <param name="blurRadius">The blur radius of the shadow.</param>
/// <param name="spreadRadius">The spread radius of the shadow.</param>
/// <param name="color">The color of the shadow.</param>
public CssShadowValue(Boolean inset, ICssValue offsetX, ICssValue offsetY, ICssValue blurRadius, ICssValue spreadRadius, Color color)
public CssShadowValue(Boolean inset, ICssValue offsetX, ICssValue offsetY, ICssValue blurRadius, ICssValue spreadRadius, Color? color)
{
_inset = inset;
_offsetX = offsetX;
Expand Down Expand Up @@ -72,9 +72,9 @@ public String CssText
parts.Add(_spreadRadius.CssText);
}

if (_color != Color.Black)
if (_color.HasValue)
{
parts.Add(_color.CssText);
parts.Add(_color.Value.CssText);
}

return String.Join(" ", parts);
Expand All @@ -84,7 +84,7 @@ public String CssText
/// <summary>
/// Gets the color of the shadow.
/// </summary>
public Color Color => _color;
public Color Color => _color ?? Color.Black;

/// <summary>
/// Gets the horizontal offset.
Expand Down

0 comments on commit 91a7444

Please sign in to comment.