Skip to content

Commit

Permalink
Merge pull request #49 from AngleSharp/devel
Browse files Browse the repository at this point in the history
Release 0.14.0
  • Loading branch information
FlorianRappl authored Apr 8, 2020
2 parents f94b973 + 496da0b commit af910d9
Show file tree
Hide file tree
Showing 78 changed files with 792 additions and 155 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
# 0.14.0

Released on Tuesday, April 7 2020.

- Added a way to compute relative dimensions (#3)
- Added render tree information incl. utilities (#4)
- Fixed issue with empty content (#42)
- Added debugger display attribute to CSS rules (#43)
- Fixed handling of CSS gradients (#45)
- Improved CSS string representation of gradients (#46)
- Exposed `IStyleCollection` for CSS info (#51)
- Fixed analysis issue with potential null selector (#52)
- Added support for the .NET Framework 4.6.1 target
- Added support for the .NET Framework 4.7.2 target

# 0.13.0

Released on Friday, September 6 2019.
Expand Down
3 changes: 3 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Thanks :heart: to all who contributed to AngleSharp.Css via issues, pull request
AngleSharp.Css contains code written by (in order of first pull request / commit):

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

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

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2013 - 2019 AngleSharp
Copyright (c) 2013 - 2020 AngleSharp

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ var config = Configuration.Default

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

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.,

```cs
var tree = document.DefaultView.Render();
var node = tree.Find(document.QuerySelector("div"));
await node.DownloadResources();
```

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.

## Advantages of AngleSharp.Css

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:
Expand Down Expand Up @@ -89,7 +99,7 @@ This project is supported by the [.NET Foundation](https://dotnetfoundation.org)

The MIT License (MIT)

Copyright (c) 2016 - 2019 AngleSharp
Copyright (c) 2016 - 2020 AngleSharp

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:

Expand Down
2 changes: 2 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ var solutionName = "AngleSharp.Css";
var frameworks = new Dictionary<String, String>
{
{ "net46", "net46" },
{ "net461", "net461" },
{ "net472", "net472" },
{ "netstandard1.3", "netstandard1.3" },
{ "netstandard2.0", "netstandard2.0" },
};
Expand Down
11 changes: 7 additions & 4 deletions src/AngleSharp.Css.Tests/AngleSharp.Css.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="AngleSharp.Xml" Version="0.13.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
<PackageReference Include="AngleSharp.Xml" Version="0.14.0" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
Expand Down
11 changes: 11 additions & 0 deletions src/AngleSharp.Css.Tests/Declarations/CssBackgroundProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -661,5 +661,16 @@ public void CssBackgroundImageDataUrlLegal()
Assert.IsTrue(property.HasValue);
Assert.AreEqual("url(\"" + url + "\")", property.Value);
}

[Test]
public void CssBackgroundImageLinearGradientLegal()
{
var source = "background-image: linear-gradient(to right, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
var property = ParseDeclaration(source);
Assert.IsTrue(property.HasValue);

var expected = "linear-gradient(90deg, rgba(255, 0, 0, 1), rgba(0, 0, 255, 1))";
Assert.AreEqual(expected, property.Value);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace AngleSharp.Css.Tests.Declarations
namespace AngleSharp.Css.Tests.Declarations
{
using NUnit.Framework;
using static CssConstructionFunctions;
Expand Down Expand Up @@ -39,7 +39,7 @@ public void CssBorderImageSourceLinearGradientLegal()
Assert.IsFalse(property.IsImportant);
Assert.IsFalse(property.IsInherited);
Assert.IsTrue(property.HasValue);
Assert.AreEqual("linear-gradient(rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
Assert.AreEqual("linear-gradient(0deg, rgba(255, 0, 0, 1), rgba(255, 255, 0, 1))", property.Value);
}

[Test]
Expand Down
12 changes: 12 additions & 0 deletions src/AngleSharp.Css.Tests/Extensions/AnalysisWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ namespace AngleSharp.Css.Tests.Extensions
using AngleSharp.Dom;
using NUnit.Framework;
using System.Text;
using System.Threading.Tasks;
using static CssConstructionFunctions;

[TestFixture]
Expand Down Expand Up @@ -277,5 +278,16 @@ public void GetCascadedValueOfTextTransformFromElementStyle()
Assert.IsNotNull(styleNormal);
Assert.AreEqual("uppercase", styleNormal.GetTextTransform());
}

[Test]
public async Task NullSelectorStillWorks_Issue52()
{
var sheet = ParseStyleSheet("a {}");
var document = await sheet.Context.OpenAsync(res => res.Content("<body></body>"));
sheet.Add(new CssStyleRule(sheet));
var sc = new StyleCollection(new[] { sheet }, new DefaultRenderDevice());
var decl = sc.ComputeCascadedStyle(document.Body);
Assert.IsNotNull(decl);
}
}
}
30 changes: 29 additions & 1 deletion src/AngleSharp.Css.Tests/Extensions/Elements.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
namespace AngleSharp.Css.Tests.Extensions
{
using NUnit.Framework;
using AngleSharp.Css.Dom;
using AngleSharp.Css.RenderTree;
using AngleSharp.Dom;
using AngleSharp.Io;
using NUnit.Framework;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

[TestFixture]
public class ElementsTests
Expand All @@ -19,5 +23,29 @@ public void SetAllStyles()
Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(1).First().GetStyle().GetBackground());
Assert.AreEqual("rgba(255, 0, 0, 1)", divs.Skip(2).First().GetStyle().GetBackground());
}

[Test]
public async Task DownloadResources()
{
var urls = new List<Url>();
var loaderOptions = new LoaderOptions
{
IsResourceLoadingEnabled = true,
Filter = (req) =>
{
urls.Add(req.Address);
return true;
},
};
var config = Configuration.Default
.WithDefaultLoader(loaderOptions)
.WithCss();
var document = "<style>div { background: url('https://avatars1.githubusercontent.com/u/10828168?s=200&v=4'); }</style><div></div>".ToHtmlDocument(config);
var tree = document.DefaultView.Render();
var node = tree.Find(document.QuerySelector("div"));
await node.DownloadResources();
Assert.AreEqual(1, urls.Count);
Assert.AreEqual("https://avatars1.githubusercontent.com/u/10828168?s=200&v=4", urls[0].Href);
}
}
}
19 changes: 19 additions & 0 deletions src/AngleSharp.Css.Tests/Parsing/StyleSheet.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
namespace AngleSharp.Css.Tests.Parsing
{
using AngleSharp.Css.Parser;
using NUnit.Framework;
using System.Threading.Tasks;

[TestFixture]
public class StyleSheet
{
[Test]
public async Task ParseEmptySheet_Issue42()
{
var sheetCode = "";
var parser = new CssParser();
var sheet = await parser.ParseStyleSheetAsync(sheetCode);
Assert.IsNotNull(sheet);
}
}
}
10 changes: 7 additions & 3 deletions src/AngleSharp.Css.Tests/Values/Gradient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public void InRadialGradient()
[Test]
public void BackgroundImageLinearGradientWithAngle()
{
var source = "background-image: linear-gradient(135deg, red, blue)";
var red = Color.Red;
var blue = Color.Blue;
var source = $"background-image: linear-gradient(135deg, {red.CssText}, {blue.CssText})";
var property = ParseDeclaration(source);
Assert.IsTrue(property.HasValue);
Assert.IsFalse(property.IsInitial);
Expand All @@ -41,8 +43,10 @@ public void BackgroundImageLinearGradientWithAngle()
Assert.IsFalse(gradient.IsRepeating);
Assert.AreEqual(Angle.TripleHalfQuarter, gradient.Angle);
Assert.AreEqual(2, gradient.Stops.Length);
Assert.AreEqual(Color.Red, gradient.Stops.First().Color);
Assert.AreEqual(Color.Blue, gradient.Stops.Last().Color);
Assert.AreEqual(red, gradient.Stops.First().Color);
Assert.AreEqual(blue, gradient.Stops.Last().Color);

Assert.AreEqual(source, property.CssText);
}

[Test]
Expand Down
Loading

0 comments on commit af910d9

Please sign in to comment.