|
| 1 | +--- |
| 2 | +title: "Getting Started" |
| 3 | +section: "AngleSharp.Css" |
| 4 | +--- |
| 5 | +# Getting Started |
| 6 | + |
| 7 | +## Requirements |
| 8 | + |
| 9 | +AngleSharp.Css comes currently in two flavors: on Windows for .NET 4.6 and in general targetting .NET Standard 2.0 platforms. |
| 10 | + |
| 11 | +Most of the features of the library do not require .NET 4.6, which means you could create your own fork and modify it to work with previous versions of the .NET-Framework. |
| 12 | + |
| 13 | +You need to have AngleSharp installed already. This could be done via NuGet: |
| 14 | + |
| 15 | +```ps1 |
| 16 | +Install-Package AngleSharp |
| 17 | +``` |
| 18 | + |
| 19 | +## Getting AngleSharp.Css over NuGet |
| 20 | + |
| 21 | +The simplest way of integrating AngleSharp.Css to your project is by using NuGet. You can install AngleSharp.Css by opening the package manager console (PM) and typing in the following statement: |
| 22 | + |
| 23 | +```ps1 |
| 24 | +Install-Package AngleSharp.Css |
| 25 | +``` |
| 26 | + |
| 27 | +You can also use the graphical library package manager ("Manage NuGet Packages for Solution"). Searching for "AngleSharp.Css" in the official NuGet online feed will find this library. |
| 28 | + |
| 29 | +## Setting up AngleSharp.Css |
| 30 | + |
| 31 | +To use AngleSharp.Css you need to add it to your `Configuration` coming from AngleSharp itself. |
| 32 | + |
| 33 | +If you just want a configuration *that works* (as close as possible to real browsers) you should use the following code: |
| 34 | + |
| 35 | +```cs |
| 36 | +var config = Configuration.Default |
| 37 | + .WithCss(); // from AngleSharp.Css |
| 38 | +``` |
| 39 | + |
| 40 | +This will register a parser for CSS related content. The CSS parsing options and more could be set with parameters of the `WithCss` method. |
| 41 | + |
| 42 | +Alternatively, all the (desired) parts may be registered individually as well. That mostly boils down to three elementary parts: |
| 43 | + |
| 44 | +- A CSS parser (implementing the `ICssParser` interface, e.g., `CssParser`) |
| 45 | +- A factory for creating CSS declarations (`IDeclarationFactory`) |
| 46 | +- The styling service that can handle CSS documents, see `CssStylingService` |
| 47 | + |
| 48 | +For an interactive DOM (i.e., to handle `style` attribute changes in the HTML document) an observer needs to be registered as well. |
| 49 | + |
| 50 | +Furthermore, for some CSSOM features (e.g., media queries) a render device is required. |
| 51 | + |
| 52 | +```cs |
| 53 | +var config = Configuration.Default |
| 54 | + .WithCss() |
| 55 | + .WithRenderDevice(new DefaultRenderDevice |
| 56 | + { |
| 57 | + DeviceHeight = 768, |
| 58 | + DeviceWidth = 1024, |
| 59 | + }); |
| 60 | +``` |
| 61 | + |
| 62 | +If no specific `IRenderDevice` (e.g., via creating an `DefaultRenderDevice` object) instance is created a default implementation will be set. |
0 commit comments