本文整理汇总了C#中AngleSharp.Parser.Css.CssParser类的典型用法代码示例。如果您正苦于以下问题:C# CssParser类的具体用法?C# CssParser怎么用?C# CssParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CssParser类属于AngleSharp.Parser.Css命名空间,在下文中一共展示了CssParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseDeclarations
internal static CssStyleDeclaration ParseDeclarations(String declarations)
{
var parser = new CssParser();
var style = new CssStyleDeclaration(parser);
style.Update(declarations);
return style;
}
示例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;
}
示例3: NewImportRule
static CssImportRule NewImportRule(String cssText)
{
var parser = new CssParser();
var rule = new CssImportRule(parser);
rule.CssText = cssText;
return rule;
}
示例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;
}
示例5: CssStyleSheet
internal CssStyleSheet(CssParser parser, String url, IElement owner)
{
_media = new MediaList(parser);
_owner = owner;
_url = url;
_rules = new CssRuleList(this);
_parser = parser;
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}