本文整理汇总了C#中AngleSharp.Parser.Css.CssParser.ParseStylesheetAsync方法的典型用法代码示例。如果您正苦于以下问题:C# CssParser.ParseStylesheetAsync方法的具体用法?C# CssParser.ParseStylesheetAsync怎么用?C# CssParser.ParseStylesheetAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AngleSharp.Parser.Css.CssParser
的用法示例。
在下文中一共展示了CssParser.ParseStylesheetAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAsyncCssParsingFromString
public async Task TestAsyncCssParsingFromString()
{
var source = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
var parser = new CssParser(Configuration.Default);
using (var task = parser.ParseStylesheetAsync(source))
{
Assert.IsTrue(task.IsCompleted);
var result = await task;
Assert.AreEqual(result, result);
Assert.AreEqual(4, result.Rules.Length);
}
}
示例2: Parse
async Task<CssStyleSheet> Parse(CssParser parser, CssStyleSheet sheet, TextSource source)
{
var evt = new CssParseStartEvent(sheet);
var events = parser.Config.Events;
if (events != null)
events.Publish(evt);
await parser.ParseStylesheetAsync(sheet, source).ConfigureAwait(false);
evt.FireEnd();
return sheet;
}
示例3: ParseStylesheetAsync
/// <summary>
/// Creates a style sheet for the given response asynchronously.
/// </summary>
/// <param name="response">
/// The response with the stream representing the source of the
/// stylesheet.
/// </param>
/// <param name="options">
/// The options with the parameters for evaluating the style.
/// </param>
/// <param name="cancel">The cancellation token.</param>
/// <returns>The task resulting in the style sheet.</returns>
public async Task<IStyleSheet> ParseStylesheetAsync(IResponse response, StyleOptions options, CancellationToken cancel)
{
var context = options.Context;
var configuration = context.Configuration;
var parser = new CssParser(_options, configuration);
var url = response.Address?.Href;
var sheet = new CssStyleSheet(parser, url, options.Element) { IsDisabled = options.IsDisabled };
var source = new TextSource(response.Content);
var tokenizer = new CssTokenizer(source);
tokenizer.Error += (_, ev) => context.Fire(ev);
var builder = new CssBuilder(tokenizer, parser);
context.Fire(new CssParseEvent(sheet, completed: false));
await parser.ParseStylesheetAsync(sheet, source).ConfigureAwait(false);
context.Fire(new CssParseEvent(sheet, completed: true));
return sheet;
}