• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Css.CssParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中AngleSharp.Parser.Css.CssParser的典型用法代码示例。如果您正苦于以下问题:C# CssParser类的具体用法?C# CssParser怎么用?C# CssParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CssParser类属于AngleSharp.Parser.Css命名空间,在下文中一共展示了CssParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ParseDeclarations

 internal static CssStyleDeclaration ParseDeclarations(String declarations)
 {
     var parser = new CssParser();
     var style = new CssStyleDeclaration(parser);
     style.Update(declarations);
     return style;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:7,代码来源:CssConstructionFunctions.cs


示例2: SetDefault

 /// <summary>
 /// Sets a new default stylesheet defined by the provided string.
 /// </summary>
 /// <param name="sourceCode">The source for a new base stylesheet.</param>
 /// <returns>The CSSOM of the parsed source.</returns>
 public ICssStyleSheet SetDefault(String sourceCode)
 {
     var parser = new CssParser(_options, Configuration.Default);
     var sheet = parser.ParseStylesheet(sourceCode);
     _default = sheet;
     return sheet;
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:12,代码来源:CssStyleEngine.cs


示例3: NewImportRule

 static CssImportRule NewImportRule(String cssText)
 {
     var parser = new CssParser();
     var rule = new CssImportRule(parser);
     rule.CssText = cssText;
     return rule;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:7,代码来源:CssImportRule.cs


示例4: CssUnknownRule

 /// <summary>
 /// Creates a new unknown rule.
 /// </summary>
 public CssUnknownRule(String name, CssParser parser)
     : base(CssRuleType.Unknown, parser)
 {
     _name = name;
     _prelude = String.Empty;
     _content = String.Empty;
 }
开发者ID:JackieyLi,项目名称:AngleSharp,代码行数:10,代码来源:CssUnknownRule.cs


示例5: CssStyleSheet

 internal CssStyleSheet(CssParser parser, String url, IElement owner)
 {
     _media = new MediaList(parser);
     _owner = owner;
     _url = url;
     _rules = new CssRuleList(this);
     _parser = parser;
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:8,代码来源:CssStyleSheet.cs


示例6: SetDefault

 /// <summary>
 /// Sets a new default stylesheet defined by the provided string.
 /// </summary>
 /// <param name="sourceCode">The source for a new base stylesheet.</param>
 /// <returns>The CSSOM of the parsed source.</returns>
 public ICssStyleSheet SetDefault(String sourceCode)
 {
     var parser = new CssParser(_options);
     var source = new TextSource(sourceCode);
     var sheet = new CssStyleSheet(parser, default(String), default(ICssStyleSheet));
     _default = Parse(parser, sheet, source).Result;
     return _default;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:13,代码来源:CssStyleEngine.cs


示例7: TestCss

 static ICssStyleSheet TestCss(String source, String title = "CSS document")
 {
     var parser = new CssParser();
     var sw = Stopwatch.StartNew();
     var sheet = parser.ParseStylesheet(source);
     sw.Stop();
     Console.WriteLine("Parsing " + title + " took " + sw.ElapsedMilliseconds + "ms");
     return sheet;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:9,代码来源:Program.cs


示例8: CreateCssSelectorTest

        static void CreateCssSelectorTest(IBrowsingContext context, String url, List<String> methods)
        {
            Console.Write("Loading " + url + " ... ");
            var document = context.OpenAsync(url).Result;
            var title = Sanatize(document.GetElementsByTagName("title")[0].TextContent);
            var content = document.GetElementsByTagName("content")[0].InnerHtml.Trim().Replace("\"", "\"\"");
            var styling = document.GetElementsByTagName("css")[0].TextContent;
            var parser = new CssParser();
            var sheet = parser.ParseStylesheet(styling);
            var selectors = new StringBuilder();
            var i = 1;

            if (methods.Contains(title))
            {
                var ltr = 'A';

                while (methods.Contains(title + ltr))
                    ltr = (Char)(ltr + 1);

                title += ltr.ToString();
            }

            foreach (var rule in sheet.Rules)
            {
                if (rule is ICssStyleRule)
                {
                    selectors.Append(@"
	        var selectorINDEX = doc.QuerySelectorAll(""SELECTOR"");
	        Assert.AreEqual(0, selectorINDEX.Length);"
                .Replace("SELECTOR", ((ICssStyleRule)rule).SelectorText)
                .Replace("INDEX", i.ToString()));
                    i++;
                }
            }

            File.AppendAllText("test.cs", @"
        /// <summary>
        /// Test taken from URL
        /// </summary>
        public void TITLE()
        {
	        var source = @""HTML"";
	        var doc = DocumentBuilder.Html(source);
	        SELECTORS
        }
"
            .Replace("URL", url)
            .Replace("TITLE", title)
            .Replace("HTML", content)
            .Replace("SELECTORS", selectors.ToString())
            );
            Console.WriteLine("success.");
            methods.Add(title);
        }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:54,代码来源:W3CCreator.cs


示例9: ParseStyleRules

		/// <summary>
		/// Applies a CSS stylesheet to the current App
		/// <para xml:lang="es">
		/// Aplica una hoja de estilo css para la aplicacion actual.
		/// </para>
		/// </summary>
		/// <param name="styleSheet">A list of css rules to be applied to the current running App
		/// <para xml:lang="es">Una lista de reglas css que se aplicaran a la aplicacion actual en ejecucion.</para>
		/// </param>
		public static void ParseStyleRules(string styleSheet)
		{
			CssParser parser = new CssParser();
			ICssStyleSheet cssStylesSheet = parser.ParseStylesheet(styleSheet);

			//get only the rules that are actually styles
			foreach (ICssStyleRule rule in cssStylesSheet.Rules.Where(rule => rule.Type == CssRuleType.Style))
			{
				ParsedStyleRules.Add(rule);
			}
		}
开发者ID:okhosting,项目名称:OKHOSTING.UI,代码行数:20,代码来源:Style.cs


示例10: TestAsyncCssParsing

 public void TestAsyncCssParsing()
 {
     var source = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
     var parser = new CssParser(source, Configuration.Default);
     var task = parser.ParseAsync();
     Assert.IsFalse(task.IsCompleted);
     Assert.IsNotNull(parser.Result);
     Assert.IsFalse(task.IsCompleted);
     task.Wait();
     Assert.IsTrue(task.IsCompleted);
     Assert.IsNotNull(parser.Result);
     Assert.AreEqual(4, parser.Result.Rules.Length);
 }
开发者ID:jogibear9988,项目名称:AngleSharp,代码行数:13,代码来源:AsyncParsing.cs


示例11: 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


示例12: CssStyleSheetComplexRoundtrip

 public void CssStyleSheetComplexRoundtrip()
 {
     var parser = new CssParser(new CssParserOptions
     {
         IsStoringTrivia = true,
         IsToleratingInvalidValues = true
     });
     var source = CssStyleEngine.DefaultSource.Replace(Environment.NewLine, "\n").Replace("\\A", "\\a").Replace("'", "\"");
     var sheet = parser.ParseStylesheet(source);
     var roundtrip = sheet.ParseTree.GetSource();
     Assert.AreEqual(source, roundtrip);
 }
开发者ID:howej,项目名称:AngleSharp,代码行数:12,代码来源:CssSheet.cs


示例13: CssStyleSheetSimpleRoundtrip

 public void CssStyleSheetSimpleRoundtrip()
 {
     var parser = new CssParser(new CssParserOptions
     {
         IsStoringTrivia = true,
         IsToleratingInvalidValues = true
     });
     var source = ".foo { color: red; } @media all /*test*/ and /*test*/ (min-width: 701px) /*test*/ { #myid { color: green; } }";
     var sheet = parser.ParseStylesheet(source);
     var roundtrip = sheet.ParseTree.GetSource();
     Assert.AreEqual(source, roundtrip);
 }
开发者ID:howej,项目名称:AngleSharp,代码行数:12,代码来源:CssSheet.cs


示例14: CssStyleSheetWithCommentInMedia

        public void CssStyleSheetWithCommentInMedia()
        {
            var parser = new CssParser(new CssParserOptions
            {
                IsStoringTrivia = true
            });
            var source = ".foo { color: red; } @media all /*test*/ and /*test*/ (min-width: 701px) /*test*/ { #myid { color: green; } }";
            var sheet = parser.ParseStylesheet(source);
            var comments = sheet.ParseTree.GetComments();
            Assert.AreEqual(3, comments.Count());

            foreach (var comment in comments)
                Assert.AreEqual("test", comment.Text);
        }
开发者ID:howej,项目名称:AngleSharp,代码行数:14,代码来源:CssSheet.cs


示例15: CssStyleRule

 /// <summary>
 /// Creates a new CSS style rule.
 /// </summary>
 internal CssStyleRule(CssParser parser)
     : base(CssRuleType.Style, parser)
 {
     _style = new CssStyleDeclaration(this);
     _selector = SimpleSelector.All;
 }
开发者ID:JackieyLi,项目名称:AngleSharp,代码行数:9,代码来源:CssStyleRule.cs


示例16: CssUnknownRule

 public CssUnknownRule(String name, CssParser parser)
     : base(CssRuleType.Unknown, parser)
 {
     _name = name;
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:5,代码来源:CssUnknownRule.cs


示例17: ParseStylesheet

 /// <summary>
 /// Creates a style sheet for the given response from a request.
 /// </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>
 /// <returns>The created style sheet.</returns>
 public IStyleSheet ParseStylesheet(IResponse response, StyleOptions options)
 {
     var parser = new CssParser(_options, options.Configuration);
     var sheet = new CssStyleSheet(parser, response.Address.Href, options.Element) 
     { 
         IsDisabled = options.IsDisabled
     };
     var source = new TextSource(response.Content);
     return Parse(parser, sheet, source).Result;
 }
开发者ID:fjwuyongzhi,项目名称:AngleSharp,代码行数:21,代码来源:CssStyleEngine.cs


示例18: CssDeclarationRule

 internal CssDeclarationRule(CssRuleType type, String name, CssParser parser)
     : base(type, parser)
 {
     _name = name;
 }
开发者ID:Wojdav,项目名称:AngleSharp,代码行数:5,代码来源:CssDeclarationRule.cs


示例19: CssStyleSheetSelectorsGetAll

 public void CssStyleSheetSelectorsGetAll()
 {
     var parser = new CssParser(new CssParserOptions
     {
         IsStoringTrivia = true
     });
     var source = ".foo { } #bar { } @media all { div { } a > b { } @media print { script[type] { } } }";
     var sheet = parser.ParseStylesheet(source);
     var roundtrip = sheet.ParseTree.GetSource();
     Assert.AreEqual(source, roundtrip);
     var selectors = sheet.ParseTree.GetAll<ISelector>();
     Assert.AreEqual(5, selectors.Count());
     var mediaRules = sheet.ParseTree.GetAll<ICssMediaRule>();
     Assert.AreEqual(2, mediaRules.Count());
     var descendentSelector = selectors.Skip(3).First();
     Assert.AreEqual("a>b", descendentSelector.Text);
     var selectorNode = sheet.ParseTree.GetAssociatedNode(descendentSelector);
     Assert.AreEqual("a > b ", selectorNode.GetSource());
 }
开发者ID:howej,项目名称:AngleSharp,代码行数:19,代码来源:CssSheet.cs


示例20: CssStyleSheetWithoutCommentsButStoringTrivia

 public void CssStyleSheetWithoutCommentsButStoringTrivia()
 {
     var parser = new CssParser(new CssParserOptions
     {
         IsStoringTrivia = true
     });
     var source = ".foo { color: red; } @media print { #myid { color: green; } }";
     var sheet = parser.ParseStylesheet(source);
     var comments = sheet.ParseTree.GetComments();
     Assert.AreEqual(0, comments.Count());
 }
开发者ID:howej,项目名称:AngleSharp,代码行数:11,代码来源:CssSheet.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Runtime.ANTLRInputStream类代码示例发布时间:2022-05-24
下一篇:
C# Dom.MutationObserver类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap