Ejemplo n.º 1
0
 public static void StyleFromSource(CSSStyleSheet sheet, String source)
 {
     if (sheet.Options.IsStyling)
     {
         var parser = new CssParser(sheet, source);
         parser.Parse();
     }
 }
Ejemplo n.º 2
0
 static void TestCSS(string source, string title = "the stylesheet")
 {
     var parser = new CssParser(source);
     var sw = Stopwatch.StartNew();
     var doc = parser.Result;
     sw.Stop();
     Console.WriteLine("Parsing " + title + " took ... " + sw.ElapsedMilliseconds + "ms");
 }
Ejemplo n.º 3
0
 public static async Task StyleFromUrl(CSSStyleSheet sheet, String url, CancellationToken cancel)
 {
     if (sheet.Options.IsStyling && Configuration.UseDefaultHttpRequester)
     {
         var stream = await GetFromUrl(url, cancel);
         var parser = new CssParser(sheet, stream);
         parser.Parse();
     }
 }
Ejemplo n.º 4
0
 public static async Task StyleFromUrl(CSSStyleSheet sheet, String url, CancellationToken cancel)
 {
     if (sheet.Options.IsStyling)
     {
         var stream = await GetFromUrl(url, cancel);
         var parser = new CssParser(sheet, stream);
         parser.Parse();
     }
 }
Ejemplo n.º 5
0
 static CSSStyleSheet TestCSS(String source, String title = "CSS document")
 {
     var parser = new CssParser(source);
     var sw = Stopwatch.StartNew();
     var doc = parser.Result;
     sw.Stop();
     Console.WriteLine("Parsing " + title + " took ... " + sw.ElapsedMilliseconds + "ms");
     return doc;
 }
Ejemplo n.º 6
0
        public static void StyleFromUrl(CSSStyleSheet sheet, String url)
        {
            //TODO we need the IoC container to resolve stream getters etc.
            return;

            var stream = Stream(url);
            var parser = new CssParser(sheet, stream);
            parser.Parse();
        }
Ejemplo n.º 7
0
 public void TestAsyncCssParsing()
 {
     var source = "h1 { color: red; } h2 { color: blue; } p { font-family: Arial; } div { margin: 10 }";
     var parser = new CssParser(source);
     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.CssRules.Length);
 }
 public CssSupportsState(CssTokenizer tokenizer, CssParser parser)
     : base(tokenizer, parser)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Takes a string and transforms it into a list of CSS values.
 /// </summary>
 /// <param name="source">The string to parse.</param>
 /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
 /// <returns>The CSSValueList object.</returns>
 internal static CSSValueList ParseValueList(String source, Boolean quirksMode = false)
 {
     var parser = new CssParser(source);
     parser.IsQuirksMode = quirksMode;
     parser.ignore = false;
     var it = parser.tokenizer.Iterator;
     return parser.CreateValueList(it);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Takes a string and transforms it into a CSS keyframe rule.
        /// </summary>
        /// <param name="rule">The string to parse.</param>
        /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
        /// <returns>The CSSKeyframeRule object.</returns>
        internal static CSSKeyframeRule ParseKeyframeRule(String rule, Boolean quirksMode = false)
        {
            var parser = new CssParser(rule);
            parser.IsQuirksMode = quirksMode;
            parser.ignore = false;
            var it = parser.tokenizer.Iterator;

            if (SkipToNextNonWhitespace(it))
            {
                if (it.Current.Type == CssTokenType.Cdo || it.Current.Type == CssTokenType.Cdc)
                    throw new DOMException(ErrorCode.SyntaxError);

                return parser.CreateKeyframeRule(it);
            }

            return null;
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Takes a string and transforms it into a CSS value.
 /// </summary>
 /// <param name="source">The string to parse.</param>
 /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
 /// <returns>The CSSValue object.</returns>
 public static CSSValue ParseValue(String source, Boolean quirksMode = false)
 {
     var parser = new CssParser(source);
     parser.IsQuirksMode = quirksMode;
     parser.ignore = false;
     var it = parser.tokenizer.Iterator;
     SkipToNextNonWhitespace(it);
     return parser.CreateValue(it);
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Takes a string and transforms it into a CSS stylesheet.
 /// </summary>
 /// <param name="stylesheet">The string to parse.</param>
 /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
 /// <returns>The CSSStyleSheet object.</returns>
 public static CSSStyleSheet ParseStyleSheet(String stylesheet, Boolean quirksMode = false)
 {
     var parser = new CssParser(stylesheet);
     parser.IsQuirksMode = quirksMode;
     return parser.Result;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Takes a string and transforms it into a selector object.
        /// </summary>
        /// <param name="selector">The string to parse.</param>
        /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
        /// <returns>The Selector object.</returns>
        public static Selector ParseSelector(String selector, Boolean quirksMode = false)
        {
            var parser = new CssParser(selector);
            parser.IsQuirksMode = quirksMode;
            var tokens = parser.tokenizer.Iterator;
            var ctor = new CssSelectorConstructor();

            while (tokens.MoveNext())
                ctor.PickSelector(tokens);

            return ctor.Result;
        }
Ejemplo n.º 14
0
 public CssFontFaceState(CssTokenizer tokenizer, CssParser parser)
     : base(tokenizer, parser)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Takes a string and transforms it into CSS declarations.
 /// </summary>
 /// <param name="declarations">The string to parse.</param>
 /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
 /// <returns>The CSSStyleDeclaration object.</returns>
 public static CSSStyleDeclaration ParseDeclarations(String declarations, Boolean quirksMode = false)
 {
     var parser = new CssParser(declarations);
     parser.IsQuirksMode = quirksMode;
     parser.ignore = false;
     var it = parser.tokenizer.Iterator;
     var decl = new CSSStyleDeclaration();
     parser.AppendDeclarations(it, decl.List);
     return decl;
 }
Ejemplo n.º 16
0
 public CssDocumentState(CssTokenizer tokenizer, CssParser parser)
     : base(tokenizer, parser)
 {
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Takes a string and transforms it into a CSS rule.
        /// </summary>
        /// <param name="rule">The string to parse.</param>
        /// <param name="quirksMode">Optional: The status of the quirks mode flag (usually not set).</param>
        /// <returns>The CSSRule object.</returns>
        public static CSSRule ParseRule(String rule, Boolean quirksMode = false)
        {
            var parser = new CssParser(rule);
            parser.ignore = false;
            parser.IsQuirksMode = quirksMode;
            var it = parser.tokenizer.Iterator;

            if (SkipToNextNonWhitespace(it))
            {
                if (it.Current.Type == CssTokenType.Cdo || it.Current.Type == CssTokenType.Cdc)
                    throw new DOMException(ErrorCode.SyntaxError);

                return (it.Current.Type == CssTokenType.AtKeyword) ? parser.CreateAtRule(it) : parser.CreateStyleRule(it);
            }

            return new CSSUnknownRule();
        }
Ejemplo n.º 18
0
        private static ICssStyleSheet Parse(String source)
        {
            var parser = new CssParser();

            return(parser.ParseStyleSheet(source));
        }