diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b6a2764..fe97872e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Released on Thursday, April 22 2021. - Added `fill` declaration (#59) +- Added support for legacy `linear-gradient` syntax (#66) - Fixed parsing of `background: none` (#65) - Fixed issues with brackets being removed for `calc` expressions (#67) - Fixed issue throwing in `grid-template: none` serializations (#63, #68) diff --git a/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs b/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs index 1fe10142..bb5c2d02 100644 --- a/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs +++ b/src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs @@ -696,5 +696,17 @@ public void CssBackgroundImageLinearGradientLegal() var expected = "linear-gradient(90deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))"; Assert.AreEqual(expected, property.Value); } + + [Test] + public void CssBackgroundImageNotParsed_Issue66() + { + var source = "background-image: linear-gradient(top,#FFFFFF,#FFFFFF,#f8f8f8,#eeeeee)"; + var property = ParseDeclaration(source); + Assert.IsTrue(property.HasValue); + + var expected = "linear-gradient(0deg, rgba(255, 255, 255, 1), rgba(255, 255, 255, 1), rgba(248, 248, 248, 1), rgba(238, 238, 238, 1))"; + Assert.AreEqual(expected, property.Value); + } } } + diff --git a/src/AngleSharp.Css/AngleSharp.Css.csproj b/src/AngleSharp.Css/AngleSharp.Css.csproj index ac1a12b6..5b59d267 100644 --- a/src/AngleSharp.Css/AngleSharp.Css.csproj +++ b/src/AngleSharp.Css/AngleSharp.Css.csproj @@ -1,9 +1,9 @@ - + AngleSharp.Css AngleSharp.Css - netstandard1.3;netstandard2.0 - netstandard1.3;netstandard2.0;net46;net461;net472 + netstandard2.0 + netstandard2.0;net46;net461;net472 true Key.snk true @@ -24,11 +24,6 @@ - - - - - false diff --git a/src/AngleSharp.Css/Parser/Micro/GradientParser.cs b/src/AngleSharp.Css/Parser/Micro/GradientParser.cs index 651cc915..996073ed 100644 --- a/src/AngleSharp.Css/Parser/Micro/GradientParser.cs +++ b/src/AngleSharp.Css/Parser/Micro/GradientParser.cs @@ -21,18 +21,10 @@ public static ICssGradientFunctionValue ParseGradient(this StringSource source) var pos = source.Index; var ident = source.ParseIdent(); - if (ident != null) + if (ident != null && source.Current == Symbols.RoundBracketOpen && GradientFunctions.TryGetValue(ident, out var function)) { - if (source.Current == Symbols.RoundBracketOpen) - { - var function = default(Func); - - if (GradientFunctions.TryGetValue(ident, out function)) - { - source.SkipCurrentAndSpaces(); - return function.Invoke(source); - } - } + source.SkipCurrentAndSpaces(); + return function.Invoke(source); } source.BackTo(pos); @@ -181,38 +173,54 @@ private static ICssValue ParseLinearAngle(StringSource source) { if (source.IsIdentifier(CssKeywords.To)) { - var angle = Angle.Zero; - source.SkipSpacesAndComments(); - var a = source.ParseIdent(); source.SkipSpacesAndComments(); - var b = source.ParseIdent(); - var keyword = default(String); - - if (a != null && b != null) - { - if (a.IsOneOf(CssKeywords.Top, CssKeywords.Bottom)) - { - var t = b; - b = a; - a = t; - } + return ParseLinearAngleKeywords(source); + } + else + { + // This is for backwards compatibility. Usually only "to" syntax is supported. + var pos = source.Index; + var test = source.ParseIdent(); + source.BackTo(pos); - keyword = String.Concat(a, " ", b); - } - else if (a != null) + if (test != null && Map.GradientAngles.ContainsKey(test)) { - keyword = a; + return ParseLinearAngleKeywords(source); } + } + + return source.ParseAngleOrCalc(); + } - if (keyword != null && Map.GradientAngles.TryGetValue(keyword, out angle)) + private static ICssValue ParseLinearAngleKeywords(StringSource source) + { + var a = source.ParseIdent(); + source.SkipSpacesAndComments(); + var b = source.ParseIdent(); + var keyword = default(String); + + if (a != null && b != null) + { + if (a.IsOneOf(CssKeywords.Top, CssKeywords.Bottom)) { - return angle; + var t = b; + b = a; + a = t; } - return null; + keyword = String.Concat(a, " ", b); + } + else if (a != null) + { + keyword = a; } - return source.ParseAngleOrCalc(); + if (keyword != null && Map.GradientAngles.TryGetValue(keyword, out var angle)) + { + return angle; + } + + return null; } private static RadialOptions? ParseRadialOptions(StringSource source)