internal void AppendDeclarations(StyleDeclaration style, string declarations) { var tokenizer = CreateTokenizer(declarations); var builder = new StylesheetComposer(tokenizer, this); builder.FillDeclarations(style); }
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); }
internal static StyleDeclaration ParseDeclarations(string declarations, bool quirksMode = false) { var decl = new StyleDeclaration(); AppendDeclarations(decl, declarations, quirksMode); return(decl); }
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); }
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; }
public KeyframeRule() { Declarations = new StyleDeclaration(); RuleType = RuleType.Keyframe; }
public StyleRule(StyleDeclaration declarations) { RuleType = RuleType.Style; _declarations = declarations; }
public KeyframeRule() { Declarations = new StyleDeclaration(); RuleType = RuleType.Keyframe; _values = new List <string>(); }
public FontFaceRule() { _declarations = new StyleDeclaration(); RuleType = RuleType.FontFace; }
public FontFaceRule() { _declarations = new StyleDeclaration(); RuleType = RuleType.FontFace; AtRuleKeyword = "font-face"; }
public PageRule() { _declarations = new StyleDeclaration(); RuleType = RuleType.Page; }
public GenericRule() { Declarations = new StyleDeclaration(); }
public ViewportRule(StyleDeclaration declarations) { RuleType = RuleType.Viewport; _declarations = declarations; AtRuleKeyword = "viewport"; }