public override CssNode CloneNode() { var clone = new StyleRule(selector); foreach (var child in Children) { clone.Add(child.CloneNode()); } return clone; }
public override CssNode CloneNode() { var clone = new StyleRule(Selector) { Depth = Depth }; foreach (var child in Children) { clone.Add(child.CloneNode()); } return(clone); }
public static CssSelector ExpandSelector(StyleRule rule) { var parts = new Stack<CssSelector>(); parts.Push(rule.Selector); StyleRule current = rule; while ((current = current.Parent as StyleRule) != null) { parts.Push(current.Selector); if (parts.Count > 6) { throw new Exception(string.Format("May not nest more than 6 levels deep. Was {0}. ", string.Join(" ", parts))); } } var i = 0; var sb = new StringBuilder(); foreach (var selector in parts) { if (selector.Contains("&")) { var x = selector.ToString().Replace("&", sb.ToString()); sb.Clear(); sb.Append(x); i++; continue; } if (i != 0) sb.Append(" "); i++; // h1, h2, h3 if (selector.Count > 1) { var parentSelector = sb.ToString(); sb.Clear(); var c = GetSelector(parts.Skip(i)); var q = 0; foreach (var a in selector) { if (q != 0) sb.Append(", "); sb.Append(parentSelector + a); if (c != null) { sb.Append(" " + c); } q++; } break; } else { sb.Append(selector); } } return new CssSelector(sb.ToString()); }
public IEnumerable<CssRule> ExpandStyleRule(StyleRule rule, CssRule parent) { var newRule = new StyleRule(ExpandSelector(rule)); foreach (var childNode in rule.Children.ToArray()) { if (childNode is StyleRule) { var childRule = (StyleRule)childNode; foreach (var r in ExpandStyleRule(childRule, rule)) { yield return r; } } else { newRule.Add(childNode); } } parent.Remove(rule); // Remove from parent node after it's been processed if (newRule.HasChildren) yield return newRule; }
public void WriteStyleRule(StyleRule rule, int level) { WriteSelector(rule.Selector); writer.Write(" "); WriteBlock(rule, level); }