当前位置: 首页>>代码示例>>C#>>正文


C# CssParser.ParseStylesheetAsync方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:14,代码来源:AsyncParsing.cs

示例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;
        }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:12,代码来源:CssStyleEngine.cs

示例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;
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:28,代码来源:CssStyleEngine.cs


注:本文中的AngleSharp.Parser.Css.CssParser.ParseStylesheetAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。