internal async Task <CssStyleSheet> ParseStylesheetAsync(CssStyleSheet sheet, TextSource source) { await source.PrefetchAllAsync(CancellationToken.None).ConfigureAwait(false); var tokenizer = new CssTokenizer(source); var start = tokenizer.GetCurrentPosition(); var builder = new CssBuilder(tokenizer, this); var document = sheet.GetDocument() as Document; var tasks = new List <Task>(); var end = builder.CreateRules(sheet); var range = new TextRange(start, end); sheet.SourceCode = new TextView(range, source); foreach (var rule in sheet.Rules) { if (rule.Type == CssRuleType.Charset) { continue; } else if (rule.Type != CssRuleType.Import) { break; } else { var import = (CssImportRule)rule; tasks.Add(import.LoadStylesheetFromAsync(document)); } } await TaskEx.WhenAll(tasks).ConfigureAwait(false); return(sheet); }
public void CssParserIdentifier() { var teststring = "h1 { background: blue; }"; var tokenizer = new CssTokenizer(new TextSource(teststring), null); var token = tokenizer.Get(); Assert.AreEqual(CssTokenType.Ident, token.Type); }
public void CssTokenizerOnlyCarriageReturn() { var teststring = "\r"; var tokenizer = new CssTokenizer(new TextSource(teststring), null); var token = tokenizer.Get(); Assert.AreEqual("\n", token.Data); }
public void CssTokenizerOnlyLineFeed() { var teststring = "\n"; var tokenizer = new CssTokenizer(new TextSource(teststring), null); var token = tokenizer.Get(); Assert.AreEqual("\n", token.Data); }
public void CssParserAtRule() { var teststring = "@media { background: blue; }"; var tokenizer = new CssTokenizer(new TextSource(teststring), null); var token = tokenizer.Get(); Assert.AreEqual(CssTokenType.AtKeyword, token.Type); }
public void CssTokenizerCarriageReturnLineFeed() { var teststring = "\r\n"; var tokenizer = new CssTokenizer(new TextSource(teststring)); var token = tokenizer.Get(); Assert.AreEqual("\n", token.Data); }
public void CssParserUrlSingleQuoted() { var url = "http://someurl"; var teststring = "url('" + url + "')"; var tokenizer = new CssTokenizer(new TextSource(teststring), null); var token = tokenizer.Get(); Assert.AreEqual(url, token.Data); }
public CssBuilder(CssTokenizer tokenizer, CssParser parser) { _tokenizer = tokenizer; _parser = parser; _nodes = new Stack <CssNode>(); if (parser.Options.IsStoringTrivia) { _nodes.Push(new CssNode()); } }
internal ICssStyleSheet ParseStylesheet(TextSource source) { var sheet = new CssStyleSheet(this); var tokenizer = new CssTokenizer(source); var start = tokenizer.GetCurrentPosition(); var builder = new CssBuilder(tokenizer, this); var end = builder.CreateRules(sheet); var range = new TextRange(start, end); sheet.SourceCode = new TextView(range, source); return(sheet); }
public CssBuilder(CssTokenizer tokenizer, CssParser parser) { _tokenizer = tokenizer; _parser = parser; }
public CssBuilder(CssTokenizer tokenizer, CssParser parser) { _tokenizer = tokenizer; _parser = parser; _nodes = new Stack <CssNode>(); }
/// <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; }
public CssParseState(CssTokenizer tokenizer, CssParser parser) { _tokenizer = tokenizer; _parser = parser; }