Provided Services
Calling WithCss() registers a set of CSS-related services in the AngleSharp configuration.
What WithCss() Registers
From the default configuration extension:
ICssDefaultStyleSheetProvider-> default stylesheet provider,IFeatureValidatorFactory-> media feature validators,IDocumentFunctionFactory-> document function support,IPseudoElementFactory-> pseudo-element construction,IDeclarationFactory-> declaration metadata + value conversion,ICssParser-> parser instance using optionalCssParserOptions,IStylingService->CssStylingServicefor CSS MIME handling,- CSS observer service (
Factory.Observer) for style mutation integration. IPseudoClassSelectorFactory-> wrapped so any recognized pseudo-class can be forced per element viaSetPseudoClass(...)(see Core Interfaces).
Quick Service Retrieval
C#
using AngleSharp;
using AngleSharp.Css;
using AngleSharp.Css.Parser;
var context = BrowsingContext.New(Configuration.Default.WithCss());
var parser = context.GetService<ICssParser>();
var defaultSheets = context.GetServices<ICssDefaultStyleSheetProvider>();
var declarationFactory = context.GetService<IDeclarationFactory>();
Styling Service Role
CssStylingService is the IStylingService implementation that:
- recognizes CSS MIME types,
- creates
ICssStyleSheetobjects for responses, - delegates parsing to
ICssParser.
This is the bridge that enables stylesheet loading from DOM resources.
Render-Related Service
WithRenderDevice(...) registers IRenderDevice, which is consumed by:
GetComputedStyle(...),- render-tree generation (
window.Render(...)), - media query feature validation.
Optional Painting Services
WithCss() registers nothing for the Painting API; the following services can be added to the configuration with With(...):
IPaintWorkletModuleLoaderruns the modules given toCSS.paintWorklet.addModule(), e.g., with a scripting engine. Without it,AddModulefails with aNotSupportedError.IPaintRenderingContextFactorycreates the rendering contexts paint definitions draw with, e.g., into a bitmap. Without it, the operations are recorded by aRecordingPaintRenderingContext2D.
Practical Checks
C#
var context = BrowsingContext.New(
Configuration.Default
.WithCss()
.WithRenderDevice());
var hasParser = context.GetService<ICssParser>() is not null;
var hasDevice = context.GetService<IRenderDevice>() is not null;
Console.WriteLine($"Parser: {hasParser}, RenderDevice: {hasDevice}");
Edit this page on GitHub
View as Markdown
Synced from
b358610