Skip to content

Commit 8f959a7

Browse files
committed
Updated changelog
1 parent 5f1c008 commit 8f959a7

File tree

4 files changed

+57
-41
lines changed

4 files changed

+57
-41
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Released on Thursday, April 22 2021.
44

55
- Added `fill` declaration (#59)
6+
- Added support for legacy `linear-gradient` syntax (#66)
67
- Fixed parsing of `background: none` (#65)
78
- Fixed issues with brackets being removed for `calc` expressions (#67)
89
- Fixed issue throwing in `grid-template: none` serializations (#63, #68)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,5 +696,17 @@ public void CssBackgroundImageLinearGradientLegal()
696696
var expected = "linear-gradient(90deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
697697
Assert.AreEqual(expected, property.Value);
698698
}
699+
700+
[Test]
701+
public void CssBackgroundImageNotParsed_Issue66()
702+
{
703+
var source = "background-image: linear-gradient(top,#FFFFFF,#FFFFFF,#f8f8f8,#eeeeee)";
704+
var property = ParseDeclaration(source);
705+
Assert.IsTrue(property.HasValue);
706+
707+
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))";
708+
Assert.AreEqual(expected, property.Value);
709+
}
699710
}
700711
}
712+

src/AngleSharp.Css/AngleSharp.Css.csproj

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<AssemblyName>AngleSharp.Css</AssemblyName>
44
<RootNamespace>AngleSharp.Css</RootNamespace>
5-
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard1.3;netstandard2.0</TargetFrameworks>
6-
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard1.3;netstandard2.0;net46;net461;net472</TargetFrameworks>
5+
<TargetFrameworks Condition=" '$(OS)' != 'Windows_NT' ">netstandard2.0</TargetFrameworks>
6+
<TargetFrameworks Condition=" '$(OS)' == 'Windows_NT' ">netstandard2.0;net46;net461;net472</TargetFrameworks>
77
<SignAssembly>true</SignAssembly>
88
<AssemblyOriginatorKeyFile>Key.snk</AssemblyOriginatorKeyFile>
99
<GenerateDocumentationFile>true</GenerateDocumentationFile>
@@ -24,11 +24,6 @@
2424
<PackageReference Include="AngleSharp" Version="0.15.0" />
2525
</ItemGroup>
2626

27-
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
28-
<PackageReference Include="System.Net.Requests" Version="4.3.0" />
29-
<PackageReference Include="System.Reflection.TypeExtensions" Version="4.7.0" />
30-
</ItemGroup>
31-
3227
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
3328
<DelaySign>false</DelaySign>
3429
</PropertyGroup>

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

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,10 @@ public static ICssGradientFunctionValue ParseGradient(this StringSource source)
2121
var pos = source.Index;
2222
var ident = source.ParseIdent();
2323

24-
if (ident != null)
24+
if (ident != null && source.Current == Symbols.RoundBracketOpen && GradientFunctions.TryGetValue(ident, out var function))
2525
{
26-
if (source.Current == Symbols.RoundBracketOpen)
27-
{
28-
var function = default(Func<StringSource, ICssGradientFunctionValue>);
29-
30-
if (GradientFunctions.TryGetValue(ident, out function))
31-
{
32-
source.SkipCurrentAndSpaces();
33-
return function.Invoke(source);
34-
}
35-
}
26+
source.SkipCurrentAndSpaces();
27+
return function.Invoke(source);
3628
}
3729

3830
source.BackTo(pos);
@@ -181,38 +173,54 @@ private static ICssValue ParseLinearAngle(StringSource source)
181173
{
182174
if (source.IsIdentifier(CssKeywords.To))
183175
{
184-
var angle = Angle.Zero;
185-
source.SkipSpacesAndComments();
186-
var a = source.ParseIdent();
187176
source.SkipSpacesAndComments();
188-
var b = source.ParseIdent();
189-
var keyword = default(String);
190-
191-
if (a != null && b != null)
192-
{
193-
if (a.IsOneOf(CssKeywords.Top, CssKeywords.Bottom))
194-
{
195-
var t = b;
196-
b = a;
197-
a = t;
198-
}
177+
return ParseLinearAngleKeywords(source);
178+
}
179+
else
180+
{
181+
// This is for backwards compatibility. Usually only "to" syntax is supported.
182+
var pos = source.Index;
183+
var test = source.ParseIdent();
184+
source.BackTo(pos);
199185

200-
keyword = String.Concat(a, " ", b);
201-
}
202-
else if (a != null)
186+
if (test != null && Map.GradientAngles.ContainsKey(test))
203187
{
204-
keyword = a;
188+
return ParseLinearAngleKeywords(source);
205189
}
190+
}
191+
192+
return source.ParseAngleOrCalc();
193+
}
206194

207-
if (keyword != null && Map.GradientAngles.TryGetValue(keyword, out angle))
195+
private static ICssValue ParseLinearAngleKeywords(StringSource source)
196+
{
197+
var a = source.ParseIdent();
198+
source.SkipSpacesAndComments();
199+
var b = source.ParseIdent();
200+
var keyword = default(String);
201+
202+
if (a != null && b != null)
203+
{
204+
if (a.IsOneOf(CssKeywords.Top, CssKeywords.Bottom))
208205
{
209-
return angle;
206+
var t = b;
207+
b = a;
208+
a = t;
210209
}
211210

212-
return null;
211+
keyword = String.Concat(a, " ", b);
212+
}
213+
else if (a != null)
214+
{
215+
keyword = a;
213216
}
214217

215-
return source.ParseAngleOrCalc();
218+
if (keyword != null && Map.GradientAngles.TryGetValue(keyword, out var angle))
219+
{
220+
return angle;
221+
}
222+
223+
return null;
216224
}
217225

218226
private static RadialOptions? ParseRadialOptions(StringSource source)

0 commit comments

Comments
 (0)