コード例 #1
0
        /// <summary>
        /// Creates a new style rule from the given source.
        /// </summary>
        /// <param name="source">The token iterator.</param>
        /// <returns>The style rule.</returns>
        CSSStyleRule CreateStyleRule(IEnumerator <CssToken> source)
        {
            var style = new CSSStyleRule();
            var ctor  = new CssSelectorConstructor();

            ctor.IgnoreErrors      = ignore;
            style.ParentStyleSheet = sheet;
            style.ParentRule       = CurrentRule;
            open.Push(style);

            do
            {
                if (source.Current.Type == CssTokenType.CurlyBracketOpen)
                {
                    if (SkipToNextNonWhitespace(source))
                    {
                        var tokens = LimitToCurrentBlock(source);
                        AppendDeclarations(tokens.GetEnumerator(), style.Style.List);
                    }

                    break;
                }

                ctor.PickSelector(source);
            }while (source.MoveNext());

            style.Selector = ctor.Result;
            open.Pop();
            return(style);
        }
コード例 #2
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);
        }