Beispiel #1
0
        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);
        }
Beispiel #2
0
        /// <summary>
        /// Takes a text source and populate the provided CSS sheet.
        /// </summary>
        internal ICssStyleSheet ParseStylesheet(CssStyleSheet sheet, TextSource source)
        {
            var tokenizer = CreateTokenizer(source, _config);
            var builder   = new CssBuilder(tokenizer, this);

            builder.CreateRules(sheet);
            sheet.ParseTree = builder.Container;
            return(sheet);
        }
Beispiel #3
0
        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);
        }