Skip to content

Commit 183022f

Browse files
committed
Documentation improvements
1 parent 4bd41ad commit 183022f

File tree

11 files changed

+74
-11
lines changed

11 files changed

+74
-11
lines changed

doc/API.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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.

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).
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace AngleSharp.Css.Values
2+
{
3+
using AngleSharp.Css.Dom;
4+
5+
/// <summary>
6+
/// Represents a special CSS value.
7+
/// </summary>
8+
public interface ICssSpecialValue : ICssValue
9+
{
10+
/// <summary>
11+
/// Gets the underlying CSS value the special one
12+
/// is referring to (e.g., the initial value).
13+
/// </summary>
14+
ICssValue Value { get; }
15+
}
16+
}

src/AngleSharp.Css/Values/Raws/CssInheritValue.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
66
/// <summary>
77
/// Represents the CSS inherit value.
88
/// </summary>
9-
sealed class CssInheritValue : ICssValue
9+
sealed class CssInheritValue : ICssSpecialValue
1010
{
1111
private CssInheritValue()
1212
{
@@ -17,6 +17,11 @@ private CssInheritValue()
1717
/// </summary>
1818
public static readonly CssInheritValue Instance = new CssInheritValue();
1919

20+
/// <summary>
21+
/// Gets the referring value.
22+
/// </summary>
23+
public ICssValue Value => null;
24+
2025
/// <summary>
2126
/// Gets the CSS text representation.
2227
/// </summary>

src/AngleSharp.Css/Values/Raws/CssInitialValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
66
/// <summary>
77
/// Represents the CSS initial value.
88
/// </summary>
9-
struct CssInitialValue : ICssValue
9+
struct CssInitialValue : ICssSpecialValue
1010
{
1111
#region Fields
1212

src/AngleSharp.Css/Values/Raws/CssUnsetValue.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace AngleSharp.Css.Values
66
/// <summary>
77
/// Represents a CSS unset value.
88
/// </summary>
9-
struct CssUnsetValue : ICssValue
9+
struct CssUnsetValue : ICssSpecialValue
1010
{
1111
#region Fields
1212

src/AngleSharp.Performance.Css/AngleSharp.Performance.Css.csproj

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0</TargetFrameworks>
3+
<TargetFramework>netcoreapp2.1</TargetFramework>
44
<ApplicationIcon />
55
<OutputType>Exe</OutputType>
66
<StartupObject />
7+
<AutoGenerateBindingRedirects>false</AutoGenerateBindingRedirects>
8+
</PropertyGroup>
9+
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
10+
<PlatformTarget>AnyCPU</PlatformTarget>
711
</PropertyGroup>
812

913
<ItemGroup>
@@ -16,6 +20,7 @@
1620

1721
<ItemGroup>
1822
<PackageReference Include="Alba.CsCss" version="1.0.1.0" />
23+
<PackageReference Include="AngleSharp" Version="0.12.0" />
1924
<PackageReference Include="ExCSS" version="2.0.6" />
2025
</ItemGroup>
2126
</Project>

src/AngleSharp.Performance.Css/AngleSharpParser.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Performance.Css
1+
namespace AngleSharp.Performance.Css
22
{
33
using AngleSharp;
44
using AngleSharp.Css.Parser;
@@ -10,7 +10,7 @@ class AngleSharpParser : ITestee
1010
{
1111
IsIncludingUnknownDeclarations = true,
1212
IsIncludingUnknownRules = true,
13-
IsToleratingInvalidSelectors = true
13+
IsToleratingInvalidSelectors = true,
1414
};
1515
private static readonly CssParser parser = new CssParser(options);
1616

src/AngleSharp.Performance.Css/Program.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Performance.Css
1+
namespace AngleSharp.Performance.Css
22
{
33
using System;
44
using System.Collections.Generic;
@@ -30,13 +30,13 @@ static void Main(String[] args)
3030
{
3131
new AngleSharpParser(),
3232
new ExCssParser(),
33-
new CsCssParser()
33+
new CsCssParser(),
3434
};
3535

3636
var testsuite = new TestSuite(parsers, stylesheets.Tests, new Output(), new Warmup())
3737
{
3838
NumberOfRepeats = 5,
39-
NumberOfReRuns = 1
39+
NumberOfReRuns = 1,
4040
};
4141

4242
testsuite.Run();

src/AngleSharp.Performance.Utilities/Warmup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace AngleSharp.Performance
1+
namespace AngleSharp.Performance
22
{
33
using System;
44
using System.Reflection;

0 commit comments

Comments
 (0)