本文整理汇总了C#中AngleSharp.Parser.Css.CssParser.ParseStylesheet方法的典型用法代码示例。如果您正苦于以下问题:C# CssParser.ParseStylesheet方法的具体用法?C# CssParser.ParseStylesheet怎么用?C# CssParser.ParseStylesheet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AngleSharp.Parser.Css.CssParser
的用法示例。
在下文中一共展示了CssParser.ParseStylesheet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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);
}
}
示例4: 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);
}
示例5: CssStyleSheetShouldIgnoreHtmlCommentTokens
public void CssStyleSheetShouldIgnoreHtmlCommentTokens()
{
var parser = new CssParser();
var source = "<!-- body { font-family: Verdana } div.hidden { display: none } -->";
var sheet = parser.ParseStylesheet(source);
Assert.AreEqual(2, sheet.Rules.Length);
Assert.AreEqual(CssRuleType.Style, sheet.Rules[0].Type);
var body = sheet.Rules[0] as ICssStyleRule;
Assert.AreEqual("body", body.SelectorText);
Assert.AreEqual(1, body.Style.Length);
Assert.AreEqual("Verdana", body.Style.FontFamily);
Assert.AreEqual(CssRuleType.Style, sheet.Rules[1].Type);
var div = sheet.Rules[1] as ICssStyleRule;
Assert.AreEqual("div.hidden", div.SelectorText);
Assert.AreEqual(1, div.Style.Length);
Assert.AreEqual("none", div.Style.Display);
}
示例6: 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());
}
示例7: 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);
}
示例8: 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);
}
示例9: 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);
}
示例10: Parse
static ICssStyleRule Parse(String source)
{
var parser = new CssParser();
return parser.ParseStylesheet(source).Rules[0] as ICssStyleRule;
}
示例11: CssColorFunctionsMixAllShouldWork
public void CssColorFunctionsMixAllShouldWork()
{
var parser = new CssParser();
var source = @"
.rgbNumber { color: rgb(255, 128, 0); }
.rgbPercent { color: rgb(100%, 50%, 0%); }
.rgbaNumber { color: rgba(255, 128, 0, 0.0); }
.rgbaPercent { color: rgba(100%, 50%, 0%, 0.0); }
.hsl { color: hsl(120, 100%, 50%); }
.hslAngle { color: hsl(120deg, 100%, 50%); }
.hsla { color: hsla(120, 100%, 50%, 0.25); }
.hslaAngle { color: hsla(120deg, 100%, 50%, 0.25); }
.grayNumber { color: gray(128); }
.grayPercent { color: gray(50%); }
.grayPercentAlpha { color: gray(50%, 0.5); }
.hwb { color: hwb(120, 60%, 20%); }
.hwbAngle { color: hwb(120deg, 60%, 20%); }
.hwbAlpha { color: hwb(120, 10%, 50%, 0.5); }
.hwbAngleAlpha { color: hwb(120deg, 10%, 50%, 0.5); }";
var sheet = parser.ParseStylesheet(source);
Assert.AreEqual(15, sheet.Rules.Length);
var rgbNumber = (sheet.Rules[0] as ICssStyleRule).Style.Color;
var rgbPercent = (sheet.Rules[1] as ICssStyleRule).Style.Color;
var rgbaNumber = (sheet.Rules[2] as ICssStyleRule).Style.Color;
var rgbaPercent = (sheet.Rules[3] as ICssStyleRule).Style.Color;
var hsl = (sheet.Rules[4] as ICssStyleRule).Style.Color;
var hslAngle = (sheet.Rules[5] as ICssStyleRule).Style.Color;
var hsla = (sheet.Rules[6] as ICssStyleRule).Style.Color;
var hslaAngle = (sheet.Rules[7] as ICssStyleRule).Style.Color;
var grayNumber = (sheet.Rules[8] as ICssStyleRule).Style.Color;
var grayPercent = (sheet.Rules[9] as ICssStyleRule).Style.Color;
var grayPercentAlpha = (sheet.Rules[10] as ICssStyleRule).Style.Color;
var hwb = (sheet.Rules[11] as ICssStyleRule).Style.Color;
var hwbAngle = (sheet.Rules[12] as ICssStyleRule).Style.Color;
var hwbAlpha = (sheet.Rules[13] as ICssStyleRule).Style.Color;
var hwbAngleAlpha = (sheet.Rules[14] as ICssStyleRule).Style.Color;
Assert.IsNotNullOrEmpty(rgbNumber);
Assert.IsNotNullOrEmpty(rgbPercent);
Assert.IsNotNullOrEmpty(rgbaPercent);
Assert.IsNotNullOrEmpty(hsl);
Assert.IsNotNullOrEmpty(hslAngle);
Assert.IsNotNullOrEmpty(hsla);
Assert.IsNotNullOrEmpty(hslaAngle);
Assert.IsNotNullOrEmpty(grayNumber);
Assert.IsNotNullOrEmpty(grayPercent);
Assert.IsNotNullOrEmpty(grayPercentAlpha);
Assert.IsNotNullOrEmpty(hwb);
Assert.IsNotNullOrEmpty(hwbAngle);
Assert.IsNotNullOrEmpty(hwbAlpha);
Assert.IsNotNullOrEmpty(hwbAngleAlpha);
}
示例12: 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());
}
示例13: Parse
CssStyleSheet Parse(CssParser parser, CssStyleSheet sheet, TextSource source)
{
using (var evt = new CssParseStartEvent(sheet))
{
var events = parser.Config.Events;
if (events != null)
events.Publish(evt);
parser.ParseStylesheet(sheet, source);
}
return sheet;
}
示例14: ParseStyleSheet
internal static ICssStyleSheet ParseStyleSheet(String source)
{
var parser = new CssParser();
return parser.ParseStylesheet(source);
}
示例15: ToCssStylesheet
public static ICssStyleSheet ToCssStylesheet(this Stream content, IConfiguration configuration = null)
{
var parser = new CssParser(configuration);
return parser.ParseStylesheet(content);
}