예제 #1
0
        internal void AppendDeclarations(StyleDeclaration style, string declarations)
        {
            var tokenizer = CreateTokenizer(declarations);
            var builder   = new StylesheetComposer(tokenizer, this);

            builder.FillDeclarations(style);
        }
예제 #2
0
        public TextPosition FillDeclarations(StyleDeclaration style)
        {
            var finalProperties = new Dictionary <string, IProperty>(StringComparer.OrdinalIgnoreCase);
            var token           = NextToken();

            _nodes.Push(style);
            ParseComments(ref token);

            while (token.IsNot(TokenType.EndOfFile, TokenType.CurlyBracketClose))
            {
                var sourceProperty     = CreateDeclarationWith(PropertyFactory.Instance.Create, ref token);
                var resolvedProperties = new[] { sourceProperty };

                if ((sourceProperty != null) && sourceProperty.HasValue)
                {
                    // For shorthand properties we need to first find out what alternate set of properties they will
                    // end up resolving into so that we can compare them with their previously parsed counterparts (if any)
                    // and determine which one takes priority over the other.
                    // Example 1: "margin-left: 5px !important; text-align:center; margin: 3px;";
                    // Example 2: "margin: 5px !important; text-align:center; margin-left: 3px;";
                    if (sourceProperty is ShorthandProperty)
                    {
                        var shorthandProperty = sourceProperty as ShorthandProperty;
                        resolvedProperties = PropertyFactory.Instance.CreateLonghandsFor(shorthandProperty.Name);
                        shorthandProperty.Export(resolvedProperties);
                    }

                    foreach (var resolvedProperty in resolvedProperties)
                    {
                        // The following relies on the fact that the tokens are processed in
                        // top-to-bottom order of how they are defined in the parsed style declaration.
                        // This handles exposing the correct value for a property when it appears multiple
                        // times in the same style declaration.
                        // Example: "background-color:green !important; text-align:center; background-color:yellow;";
                        // In this example even though background-color yellow is defined last, the previous value
                        // of green should be he one exposed given it is tagged as important.
                        // ------------------------------------------------------------------------------------------
                        // Only set this property if one of the following conditions is true:
                        // a) It was not previously added or...
                        // b) The previously added property is not tagged as important or ...
                        // c) The previously added property is tagged as important but so is this new one.
                        var shouldSetProperty =
                            !finalProperties.TryGetValue(resolvedProperty.Name, out var previousProperty) ||
                            !previousProperty.IsImportant ||
                            resolvedProperty.IsImportant;

                        if (shouldSetProperty)
                        {
                            style.SetProperty(resolvedProperty);
                            finalProperties[resolvedProperty.Name] = resolvedProperty;
                        }
                    }
                }

                ParseComments(ref token);
            }

            _nodes.Pop();
            return(token.Position);
        }
예제 #3
0
파일: Parser.cs 프로젝트: bcanzanella/ExCSS
        internal static StyleDeclaration ParseDeclarations(string declarations, bool quirksMode = false)
        {
            var decl = new StyleDeclaration();

            AppendDeclarations(decl, declarations, quirksMode);

            return(decl);
        }
예제 #4
0
파일: Parser.cs 프로젝트: bcanzanella/ExCSS
        internal static void AppendDeclarations(StyleDeclaration list, string css, bool quirksMode = false)
        {
            var parser = new Parser();//(new StyleSheet(), new StylesheetReader(declarations))


            parser.AddRuleSet(list.ParentRule ?? new StyleRule(list));

            parser._parsingContext = ParsingContext.InDeclaration;
            parser.Parse(css);
        }
예제 #5
0
        public TextPosition FillDeclarations(StyleDeclaration style)
        {
            var token = NextToken();
            _nodes.Push(style);
            ParseComments(ref token);

            while (token.IsNot(TokenType.EndOfFile, TokenType.CurlyBracketClose))
            {
                //var property = CreateDeclarationWith(Factory.Properties.Create, ref token);
                var property = CreateDeclarationWith(PropertyFactory.Instance.Create, ref token);

                if ((property != null) && property.HasValue)
                {
                    style.SetProperty(property);
                }

                ParseComments(ref token);
            }

            _nodes.Pop();
            return token.Position;
        }
예제 #6
0
 public KeyframeRule()
 {
     Declarations = new StyleDeclaration();
     RuleType     = RuleType.Keyframe;
 }
예제 #7
0
 public StyleRule(StyleDeclaration declarations)
 {
     RuleType      = RuleType.Style;
     _declarations = declarations;
 }
예제 #8
0
 public KeyframeRule()
 {
     Declarations = new StyleDeclaration();
     RuleType     = RuleType.Keyframe;
     _values      = new List <string>();
 }
예제 #9
0
 public FontFaceRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.FontFace;
 }
예제 #10
0
 public FontFaceRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.FontFace;
     AtRuleKeyword = "font-face";
 }
예제 #11
0
파일: PageRule.cs 프로젝트: thedeveus/SVG
 public PageRule()
 {
     _declarations = new StyleDeclaration();
     RuleType      = RuleType.Page;
 }
예제 #12
0
 public GenericRule()
 {
     Declarations = new StyleDeclaration();
 }
예제 #13
0
 public ViewportRule(StyleDeclaration declarations)
 {
     RuleType      = RuleType.Viewport;
     _declarations = declarations;
     AtRuleKeyword = "viewport";
 }