Skip to content

Commit e59a6e7

Browse files
authored
Merge pull request #28 from AngleSharp/devel
Release 0.12
2 parents c99d5d7 + e3ad3b3 commit e59a6e7

File tree

469 files changed

+6018
-6142
lines changed

Some content is hidden

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

469 files changed

+6018
-6142
lines changed

CHANGELOG.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,28 @@
1+
# 0.12.0
2+
3+
Released on Sunday, May 12 2019.
4+
5+
- Reference latest AngleSharp
6+
- Fixed empty value when removing properties (#14)
7+
- Returns `null` in `GetStyle` if CSS not configured (#15)
8+
- Added `pointer-events` and fixed border recombination (#16)
9+
- Fixed `stroke-width` value without unit (#18)
10+
- Fixed exception when not providing an `IRenderDevice` (#20)
11+
- Fixed missing `CssStylingService.Default` in cascade (#21)
12+
- Added extension helper `SetStyle` to modify all styles of many elements (#22)
13+
- Fixed expansion of shorthand properties to longhand (#23)
14+
- Opened CSSOM, e.g., declared `ICssFunctionValue` `public` (#24)
15+
- Introduced special converter for the `src` declaration (#25)
16+
- Fixed bug regarding CSS grid serialization (#27)
17+
- Added `DefaultRenderDevice` implementation
18+
19+
# 0.10.1
20+
21+
Released on Monday, January 7 2019.
22+
23+
- Reference latest AngleSharp
24+
- Updated reference to `System.Encoding.CodePages` (#13)
25+
126
# 0.10.0
227

328
Released on Friday, January 4 2019.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![GitHub Tag](https://img.shields.io/github/tag/AngleSharp/AngleSharp.Css.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Css/releases)
77
[![NuGet Count](https://img.shields.io/nuget/dt/AngleSharp.Css.svg?style=flat-square)](https://www.nuget.org/packages/AngleSharp.Css/)
88
[![Issues Open](https://img.shields.io/github/issues/AngleSharp/AngleSharp.Css.svg?style=flat-square)](https://github.com/AngleSharp/AngleSharp.Css/issues)
9+
[![Gitter Chat](http://img.shields.io/badge/gitter-AngleSharp/AngleSharp-blue.svg?style=flat-square)](https://gitter.im/AngleSharp/AngleSharp)
910
[![StackOverflow Questions](https://img.shields.io/stackexchange/stackoverflow/t/anglesharp.svg?style=flat-square)](https://stackoverflow.com/tags/anglesharp)
1011
[![CLA Assistant](https://cla-assistant.io/readme/badge/AngleSharp/AngleSharp.Css?style=flat-square)](https://cla-assistant.io/AngleSharp/AngleSharp.Css)
1112

@@ -28,6 +29,20 @@ This will register a parser for CSS related content. The CSS parsing options and
2829

2930
For an interactive DOM (i.e., to handle `style` attribute changes in the HTML document) an observer needs to be registered as well.
3031

32+
Furthermore, for some CSSOM features (e.g., media queries) a render device is required.
33+
34+
```cs
35+
var config = Configuration.Default
36+
.WithCss()
37+
.WithRenderDevice(new DefaultRenderDevice
38+
{
39+
DeviceHeight = 768,
40+
DeviceWidth = 1024,
41+
});
42+
```
43+
44+
If no specific `IRenderDevice` (e.g., via creating an `DefaultRenderDevice` object) instance is created a default implementation will be set.
45+
3146
## Advantages of AngleSharp.Css
3247

3348
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:
@@ -60,6 +75,16 @@ Participation in the project is highly welcome. For this project the same rules
6075

6176
If you have any question, concern, or spot an issue then please report it before opening a pull request. An initial discussion is appreciated regardless of the nature of the problem.
6277

78+
Live discussions can take place in our [Gitter chat](https://gitter.im/AngleSharp/AngleSharp), which supports using GitHub accounts.
79+
80+
This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community.
81+
82+
For more information see the [.NET Foundation Code of Conduct](https://dotnetfoundation.org/code-of-conduct).
83+
84+
## .NET Foundation
85+
86+
This project is supported by the [.NET Foundation](https://dotnetfoundation.org).
87+
6388
## License
6489

6590
The MIT License (MIT)

build.cake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ using Octokit;
1616

1717
var target = Argument("target", "Default");
1818
var configuration = Argument("configuration", "Release");
19-
var isLocal = BuildSystem.IsLocalBuild;
2019
var isRunningOnUnix = IsRunningOnUnix();
2120
var isRunningOnWindows = IsRunningOnWindows();
2221
var isRunningOnAppVeyor = AppVeyor.IsRunningOnAppVeyor;
@@ -140,7 +139,7 @@ Task("Create-Package")
140139

141140
Task("Publish-Package")
142141
.IsDependentOn("Create-Package")
143-
.WithCriteria(() => isLocal)
142+
.IsDependentOn("Run-Unit-Tests")
144143
.Does(() =>
145144
{
146145
var apiKey = EnvironmentVariable("NUGET_API_KEY");
@@ -161,8 +160,8 @@ Task("Publish-Package")
161160
});
162161

163162
Task("Publish-Release")
164-
.IsDependentOn("Publish-Package")
165-
.WithCriteria(() => isLocal)
163+
.IsDependentOn("Create-Package")
164+
.IsDependentOn("Run-Unit-Tests")
166165
.Does(() =>
167166
{
168167
var githubToken = EnvironmentVariable("GITHUB_API_TOKEN");

doc/API.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# API Documentation
2+
3+
## CSSOM - Basics
4+
5+
The CSS Object Model (CSSOM) consists of multiple parts. On the one hand we have standard Document Object Model (DOM) exposed interfaces, such as the stylesheets, styles, or rules, on the other hand we have special constructs only available in AngleSharp to dig deeper into the provided CSS.
6+
7+
The AngleSharp CSS parser can construct objects of the following high-level types:
8+
9+
- `ICssStyleSheet`, representing a full CSS stylesheet
10+
- `ICssRule`, representing a rule within a CSS stylesheet
11+
- `ICssKeyframeRule`, representing a special keyframe rule (only exposed since the DOM directly connects to it)
12+
- `ICssStyleDeclaration`, representing the keeper of CSS declarations
13+
14+
A CSS declaration is a CSS property, e.g., `color` together with its value (e.g., `red`) and priority ("important" or not). Declarations are rather complicated as they appear not only in primitive fashion as seen earlier (`color`), but also in form of *shorthands* such as `background`. In the latter case the shorthand is expanded into all contained *longhands* (e.g., `background-color`, `background-image`, ...) and stored in this primitive way. Retrieving the shorthand later on is done via a recombination of the *currently* available longhands.
15+
16+
The topic with longhands and shorthands is especially complicated in face of *defered computation*. This is the case once a calculated value is hit, which is necessary for the rule to be validated, but cannot be calculated during sheet evaluation time (i.e., the calculation has to take place with the cascade coming from the DOM). The simplest example is `var`. CSS variables are evaluated only with the cascade in mind. In this case no simple expansion of the shorthand into longhands is possible. Instead, AngleSharp will "fake" a potential expansion with a reference value, which can then be resolved later.
17+
18+
There are multiple types of rules. Depending on the type of rule other rules may be the children of the rule. While a style rule is the most elementary one (essentially just containing an `ICssStyleDeclaration` instance) one example of a container rule is the media rule. This type of rule hosts other rules.
19+
20+
## CSSOM - Values
21+
22+
The most interesting part of a CSS declaration is the value part. This is also the complicated part as values are always given in string form. The parsing is completely dependent on the type of declaration. Some fixed / known types and parsing rules exist, however, the exact setup of a declaration is completely arbitrary.
23+
24+
AngleSharp uses converters to parse a given source to an `ICssValue` instance. The converter follows the `IValueConverter` interface.
25+
26+
The `ICssValue` interface is split in various interfaces with respect to their usage.
27+
28+
![The CSSOM Value Tree](cssom-value-tree.png)
29+
30+
A converter may also implement the `IValueAggregator` interface, which indicates that the declaration behind it is actually a shorthand that can additionally merge values into a shorthand representation or split the shorthand representation into the atoms described by the shorthand.
31+
32+
For convenience some (extension) methods have been introduced to make working with the CSSOM (specifically values) simpler. The shown extension methods are placed in the `AngleSharp.Css.Dom` namespace.
33+
34+
```cs
35+
// sheet is a stylesheet, e.g., obtained from a document, with content:
36+
// p > a { border: 1px solid red }
37+
var rule = sheet.GetStyleRuleWith("p>a");
38+
var color = rule.GetValueOf("border-right-color").AsRgba();
39+
// the color is an Int32, e.g., 0xFF_FF - same as rgba(255, 0, 0, 1)
40+
```
41+
42+
The idea behind `GetStyleRuleWith` is to get the first top-level style rule that matches the given selector exactly. The text of the selector does not have to be equal to the text of the selector in the stylesheet, but it needs to be equal *semantically*, i.e., in the provided example the spaces do not matter as the semantics are not influenced by them.
43+
44+
The `GetValueOf` obtains the `ICssValue` instance behind the property with the given name. The `AsRgba` works (like all the other `As*` extension methods) against the `ICssValue` to get an elementary value out of it. This works in simple cases, but will fail, e.g., when there are multiple values available or when the primitive value is hidden in a composite one.

doc/cssom-value-tree.png

181 KB
Loading

doc/index.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# AngleSharp.Css Documentation
2+
3+
We have more detailed information regarding the following subjects:
4+
5+
- [API Documentation](API.md)
6+
7+
For help on AngleSharp itself, see [the full documentation](https://anglesharp.github.io/docs.html).

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16-
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
16+
<PackageReference Include="AngleSharp.Xml" Version="0.12.0" />
17+
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
1718
<PackageReference Include="NUnit" Version="3.11.0" />
18-
<PackageReference Include="NUnit3TestAdapter" Version="3.11.0" />
19+
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
1920
<PackageReference Include="Appveyor.TestLogger" Version="2.0.0" />
2021
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
2122
</ItemGroup>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public void CssAnimationCountDoubleIllegal()
473473
{
474474
var snippet = "animation : 10 20";
475475
var property = ParseDeclaration(snippet);
476-
Assert.IsNull(property);
476+
Assert.IsFalse(property.HasValue);
477477
}
478478

479479
[Test]

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
using AngleSharp.Css.Dom;
2+
using AngleSharp.Css.Parser;
3+
14
namespace AngleSharp.Css.Tests.Declarations
25
{
36
using NUnit.Framework;
@@ -178,7 +181,7 @@ public void CssBorderColorRedBlueGreenBlackTransparentIllegal()
178181
{
179182
var snippet = "border-color: red blue green black transparent";
180183
var property = ParseDeclaration(snippet);
181-
Assert.IsNull(property);
184+
Assert.IsFalse(property.HasValue);
182185
}
183186

184187
[Test]
@@ -246,7 +249,7 @@ public void CssBorderStyleWavyIllegal()
246249
{
247250
var snippet = "border-style: wavy";
248251
var property = ParseDeclaration(snippet);
249-
Assert.IsNull(property);
252+
Assert.IsFalse(property.HasValue);
250253
}
251254

252255
[Test]
@@ -434,7 +437,7 @@ public void CssBorderWidthZerosIllegal()
434437
{
435438
var snippet = "border-width: 0 0 0 0 0";
436439
var property = ParseDeclaration(snippet);
437-
Assert.IsNull(property);
440+
Assert.IsFalse(property.HasValue);
438441
}
439442

440443
[Test]
@@ -554,5 +557,17 @@ public void CssBorderOutSetWithNoColor()
554557
Assert.IsTrue(property.HasValue);
555558
Assert.AreEqual("1px outset", property.Value);
556559
}
560+
561+
[Test]
562+
public void CssBorderAggregation()
563+
{
564+
var expectedCss = "border: 1px solid rgba(0, 0, 0, 1)";
565+
var context = BrowsingContext.New(Configuration.Default.WithCss());
566+
var style = new CssStyleDeclaration(context);
567+
style.SetBorderWidth("1px");
568+
style.SetBorderStyle("solid");
569+
style.SetBorderColor("black");
570+
Assert.AreEqual(expectedCss, style.CssText);
571+
}
557572
}
558573
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public void CssBorderBottomLeftRadiusPxPxLegal()
1515
Assert.IsFalse(property.IsImportant);
1616
Assert.IsFalse(property.IsInherited);
1717
Assert.IsTrue(property.HasValue);
18-
Assert.AreEqual("40px 40px", property.Value);
18+
Assert.AreEqual("40px", property.Value);
1919
}
2020

2121
[Test]
@@ -155,7 +155,7 @@ public void CssBorderRadiusFiveLengthsIllegal()
155155
{
156156
var snippet = "border-radius: 2px 4px 3px 0 1px";
157157
var property = ParseDeclaration(snippet);
158-
Assert.IsNull(property);
158+
Assert.IsFalse(property.HasValue);
159159
}
160160

161161
[Test]
@@ -199,15 +199,15 @@ public void CssBorderRadiusFiveTailFractionIllegal()
199199
{
200200
var snippet = "border-radius: 4px 3px 6px 1em / 2px 4px 0 20% 0";
201201
var property = ParseDeclaration(snippet);
202-
Assert.IsNull(property);
202+
Assert.IsFalse(property.HasValue);
203203
}
204204

205205
[Test]
206206
public void CssBorderRadiusFiveHeadFractionIllegal()
207207
{
208208
var snippet = "border-radius: 4px 3px 6px 1em 0 / 2px 4px 0 20%";
209209
var property = ParseDeclaration(snippet);
210-
Assert.IsNull(property);
210+
Assert.IsFalse(property.HasValue);
211211
}
212212

213213
[Test]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public void CssColumsNumberPercenIllegal()
178178
{
179179
var snippet = "columns : 5 25% ";
180180
var property = ParseDeclaration(snippet);
181-
Assert.IsNull(property);
181+
Assert.IsFalse(property.HasValue);
182182
}
183183

184184
[Test]

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,5 +759,14 @@ public void CssGridTemplateRowsAndColumnsWithFractionsLegal()
759759
Assert.IsTrue(property.HasValue);
760760
Assert.AreEqual("100px 1fr / 50px 1fr", property.Value);
761761
}
762+
763+
[Test]
764+
public void CssRuleWithOnlyGridTemplateAreasLegal_Issue27()
765+
{
766+
var snippet = @"div#A { grid-template-areas: ""a b b"" ""a c d"" }";
767+
var rule = ParseRule(snippet);
768+
var text = rule.CssText;
769+
Assert.AreEqual(snippet, text);
770+
}
762771
}
763772
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public void CssMarginTooManyValuesIllegal()
191191
{
192192
var snippet = "margin: 10px 5% 8px 2% 3px auto";
193193
var property = ParseDeclaration(snippet);
194-
Assert.IsNull(property);
194+
Assert.IsFalse(property.HasValue);
195195
}
196196

197197
[Test]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public void CssOutlineDoubleColorIllegal()
176176
{
177177
var snippet = "outline : dotted #123456 rgb(255, 255, 255)";
178178
var property = ParseDeclaration(snippet);
179-
Assert.IsNull(property);
179+
Assert.IsFalse(property.HasValue);
180180
}
181181

182182
[Test]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void CssPaddingAutoIllegal()
9595
{
9696
var snippet = "padding: auto ";
9797
var property = ParseDeclaration(snippet);
98-
Assert.IsNull(property);
98+
Assert.IsFalse(property.HasValue);
9999
}
100100

101101
[Test]
@@ -127,7 +127,7 @@ public void CssPaddingTooManyValuesIllegal()
127127
{
128128
var snippet = "padding: 10px 5% 8px 2% 3px";
129129
var property = ParseDeclaration(snippet);
130-
Assert.IsNull(property);
130+
Assert.IsFalse(property.HasValue);
131131
}
132132

133133
[Test]

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

Lines changed: 13 additions & 1 deletion
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;
@@ -370,5 +370,17 @@ public void CssStrokeWidthNoneIllegal()
370370
Assert.IsFalse(property.IsInherited);
371371
Assert.IsFalse(property.HasValue);
372372
}
373+
374+
[Test]
375+
public void CssStrokeWithoutUnit_Issue18()
376+
{
377+
var snippet = "stroke-width: 3";
378+
var property = ParseDeclaration(snippet);
379+
Assert.AreEqual("stroke-width", property.Name);
380+
Assert.IsFalse(property.IsImportant);
381+
Assert.IsFalse(property.IsInherited);
382+
Assert.IsTrue(property.HasValue);
383+
Assert.AreEqual("3", property.Value);
384+
}
373385
}
374386
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public void CssTextDecorationIllegal()
180180
{
181181
var snippet = "text-decoration: line-pass";
182182
var property = ParseDeclaration(snippet);
183-
Assert.IsNull(property);
183+
Assert.IsFalse(property.HasValue);
184184
}
185185

186186
[Test]

0 commit comments

Comments
 (0)