Skip to content

Commit af910d9

Browse files
authored
Merge pull request #49 from AngleSharp/devel
Release 0.14.0
2 parents f94b973 + 496da0b commit af910d9

File tree

78 files changed

+792
-155
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+792
-155
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
# 0.14.0
2+
3+
Released on Tuesday, April 7 2020.
4+
5+
- Added a way to compute relative dimensions (#3)
6+
- Added render tree information incl. utilities (#4)
7+
- Fixed issue with empty content (#42)
8+
- Added debugger display attribute to CSS rules (#43)
9+
- Fixed handling of CSS gradients (#45)
10+
- Improved CSS string representation of gradients (#46)
11+
- Exposed `IStyleCollection` for CSS info (#51)
12+
- Fixed analysis issue with potential null selector (#52)
13+
- Added support for the .NET Framework 4.6.1 target
14+
- Added support for the .NET Framework 4.7.2 target
15+
116
# 0.13.0
217

318
Released on Friday, September 6 2019.

CONTRIBUTORS.md

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Thanks :heart: to all who contributed to AngleSharp.Css via issues, pull request
55
AngleSharp.Css contains code written by (in order of first pull request / commit):
66

77
* [Florian Rappl](https://github.com/FlorianRappl)
8+
* [Michał Kostrzewski](https://github.com/zeaposs)
9+
* [Jochen Kühner](https://github.com/jogibear9988)
10+
* [Tom Hazell](https://github.com/The-Nutty)
811

912
Without these awesome people AngleSharp.Css could not exist. Thanks to everyone for your contributions! :beers:
1013

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013 - 2019 AngleSharp
3+
Copyright (c) 2013 - 2020 AngleSharp
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ var config = Configuration.Default
4343

4444
If no specific `IRenderDevice` (e.g., via creating an `DefaultRenderDevice` object) instance is created a default implementation will be set.
4545

46+
Going a bit further it is possible to `Render` the current document. This render tree information can then be used to retrieve or other information, e.g.,
47+
48+
```cs
49+
var tree = document.DefaultView.Render();
50+
var node = tree.Find(document.QuerySelector("div"));
51+
await node.DownloadResources();
52+
```
53+
54+
The previous snippet renders the current document. Afterwards it retrieves a particular render tree node, which is related to the first found `div`. Then all (CSS introduced) resources are downloaded for the node, if visible.
55+
4656
## Advantages of AngleSharp.Css
4757

4858
The core library already contains the CSS selector parser and the most basic classes and interfaces for dealing with the CSSOM. AngleSharp.Css brings the following advantages and use cases to life:
@@ -89,7 +99,7 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)
8999

90100
The MIT License (MIT)
91101

92-
Copyright (c) 2016 - 2019 AngleSharp
102+
Copyright (c) 2016 - 2020 AngleSharp
93103

94104
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
95105

build.cake

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ var solutionName = "AngleSharp.Css";
44
var frameworks = new Dictionary<String, String>
55
{
66
{ "net46", "net46" },
7+
{ "net461", "net461" },
8+
{ "net472", "net472" },
79
{ "netstandard1.3", "netstandard1.3" },
810
{ "netstandard2.0", "netstandard2.0" },
911
};

src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj

+7-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@
1414
</ItemGroup>
1515

1616
<ItemGroup>
17-
<PackageReference Include="AngleSharp.Xml" Version="0.13.0" />
18-
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
19-
<PackageReference Include="NUnit" Version="3.11.0" />
20-
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
17+
<PackageReference Include="AngleSharp.Xml" Version="0.14.0" />
18+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
19+
<PackageReference Include="NUnit" Version="3.12.0" />
20+
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
21+
<PrivateAssets>all</PrivateAssets>
22+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
23+
</PackageReference>
2124
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
2225
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
2326
</ItemGroup>

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

+11
Original file line numberDiff line numberDiff line change
@@ -661,5 +661,16 @@ public void CssBackgroundImageDataUrlLegal()
661661
Assert.IsTrue(property.HasValue);
662662
Assert.AreEqual("url(\"" + url + "\")", property.Value);
663663
}
664+
665+
[Test]
666+
public void CssBackgroundImageLinearGradientLegal()
667+
{
668+
var source = "background-image: linear-gradient(to right, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
669+
var property = ParseDeclaration(source);
670+
Assert.IsTrue(property.HasValue);
671+
672+
var expected = "linear-gradient(90deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
673+
Assert.AreEqual(expected, property.Value);
674+
}
664675
}
665676
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Css.Tests.Declarations
1+
namespace AngleSharp.Css.Tests.Declarations
22
{
33
using NUnit.Framework;
44
using static CssConstructionFunctions;
@@ -39,7 +39,7 @@ public void CssBorderImageSourceLinearGradientLegal()
3939
Assert.IsFalse(property.IsImportant);
4040
Assert.IsFalse(property.IsInherited);
4141
Assert.IsTrue(property.HasValue);
42-
Assert.AreEqual("linear-gradient(rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
42+
Assert.AreEqual("linear-gradient(0deg, rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
4343
}
4444

4545
[Test]

src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs

+12
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ namespace AngleSharp.Css.Tests.Extensions
44
using AngleSharp.Dom;
55
using NUnit.Framework;
66
using System.Text;
7+
using System.Threading.Tasks;
78
using static CssConstructionFunctions;
89

910
[TestFixture]
@@ -277,5 +278,16 @@ public void GetCascadedValueOfTextTransformFromElementStyle()
277278
Assert.IsNotNull(styleNormal);
278279
Assert.AreEqual("uppercase", styleNormal.GetTextTransform());
279280
}
281+
282+
[Test]
283+
public async Task NullSelectorStillWorks_Issue52()
284+
{
285+
var sheet = ParseStyleSheet("a {}");
286+
var document = await sheet.Context.OpenAsync(res => res.Content("<body></body>"));
287+
sheet.Add(new CssStyleRule(sheet));
288+
var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
289+
var decl = sc.ComputeCascadedStyle(document.Body);
290+
Assert.IsNotNull(decl);
291+
}
280292
}
281293
}

src/AngleSharp.Css.Tests/Extensions/Elements.cs

+29-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
namespace AngleSharp.Css.Tests.Extensions
22
{
3-
using NUnit.Framework;
43
using AngleSharp.Css.Dom;
4+
using AngleSharp.Css.RenderTree;
55
using AngleSharp.Dom;
6+
using AngleSharp.Io;
7+
using NUnit.Framework;
8+
using System.Collections.Generic;
69
using System.Linq;
10+
using System.Threading.Tasks;
711

812
[TestFixture]
913
public class ElementsTests
@@ -19,5 +23,29 @@ public void SetAllStyles()
1923
Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(1).First().GetStyle().GetBackground());
2024
Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(2).First().GetStyle().GetBackground());
2125
}
26+
27+
[Test]
28+
public async Task DownloadResources()
29+
{
30+
var urls = new List<Url>();
31+
var loaderOptions = new LoaderOptions
32+
{
33+
IsResourceLoadingEnabled = true,
34+
Filter = (req) =>
35+
{
36+
urls.Add(req.Address);
37+
return true;
38+
},
39+
};
40+
var config = Configuration.Default
41+
.WithDefaultLoader(loaderOptions)
42+
.WithCss();
43+
var document = "<style>div { background: url('https://avatars1.githubusercontent.com/u/10828168?s=200&v=4'); }</style><div></div>".ToHtmlDocument(config);
44+
var tree = document.DefaultView.Render();
45+
var node = tree.Find(document.QuerySelector("div"));
46+
await node.DownloadResources();
47+
Assert.AreEqual(1, urls.Count);
48+
Assert.AreEqual("https://avatars1.githubusercontent.com/u/10828168?s=200&v=4", urls[0].Href);
49+
}
2250
}
2351
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace AngleSharp.Css.Tests.Parsing
2+
{
3+
using AngleSharp.Css.Parser;
4+
using NUnit.Framework;
5+
using System.Threading.Tasks;
6+
7+
[TestFixture]
8+
public class StyleSheet
9+
{
10+
[Test]
11+
public async Task ParseEmptySheet_Issue42()
12+
{
13+
var sheetCode = "";
14+
var parser = new CssParser();
15+
var sheet = await parser.ParseStyleSheetAsync(sheetCode);
16+
Assert.IsNotNull(sheet);
17+
}
18+
}
19+
}

src/AngleSharp.Css.Tests/Values/Gradient.cs

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public void InRadialGradient()
2929
[Test]
3030
public void BackgroundImageLinearGradientWithAngle()
3131
{
32-
var source = "background-image: linear-gradient(135deg, red, blue)";
32+
var red = Color.Red;
33+
var blue = Color.Blue;
34+
var source = $"background-image: linear-gradient(135deg, {red.CssText}, {blue.CssText})";
3335
var property = ParseDeclaration(source);
3436
Assert.IsTrue(property.HasValue);
3537
Assert.IsFalse(property.IsInitial);
@@ -41,8 +43,10 @@ public void BackgroundImageLinearGradientWithAngle()
4143
Assert.IsFalse(gradient.IsRepeating);
4244
Assert.AreEqual(Angle.TripleHalfQuarter, gradient.Angle);
4345
Assert.AreEqual(2, gradient.Stops.Length);
44-
Assert.AreEqual(Color.Red, gradient.Stops.First().Color);
45-
Assert.AreEqual(Color.Blue, gradient.Stops.Last().Color);
46+
Assert.AreEqual(red, gradient.Stops.First().Color);
47+
Assert.AreEqual(blue, gradient.Stops.Last().Color);
48+
49+
Assert.AreEqual(source, property.CssText);
4650
}
4751

4852
[Test]

0 commit comments

Comments
 (0)