public static StyleSheet Parse(TextReader reader, CssContext context = null) { var sheet = new StyleSheet(context ?? new CssContext()); var rules = new List<CssRule>(); IList<Browser> browsers = null; using (var parser = new CssParser(reader)) { foreach (var node in parser.ReadNodes()) { if (node.Kind == NodeKind.Mixin) { var mixin = (MixinNode)node; sheet.Context.Mixins.Add(mixin.Name, mixin); } else if (node.Kind == NodeKind.Directive) { var directive = (CssDirective)node; if (directive.Name == "support") { var parts = directive.Value.Split(Seperators.Space); // SpaceArray... BrowserType browserType; if (Enum.TryParse(parts[0].Trim(), true, out browserType)) { if (browsers == null) { browsers = new List<Browser>(); } var browserVersion = float.Parse(parts[parts.Length - 1].Trim(' ', '+')); browsers.Add(new Browser(browserType, browserVersion)); } } } else { sheet.AddChild(node); } } if (browsers != null) { sheet.Context.SetCompatibility(browsers.ToArray()); } } return sheet; }
public CssWriter(TextWriter writer, CssContext?context = null, CssScope?scope = null, ICssResolver?resolver = null) { this.writer = writer; this.context = context ?? new CssContext(); this.resolver = resolver; this.scope = scope ?? new CssScope(); includeCount = 0; importCount = 0; nodeCount = 0; skipMath = false; this.browserSupport = this.context.BrowserSupport; }
public CssWriter(TextWriter writer, CssContext context = null, CssScope scope = null, ICssResolver resolver = null) { #region Preconditions if (writer == null) throw new ArgumentNullException(nameof(writer)); #endregion this.writer = writer; this.context = context ?? new CssContext(); this.resolver = resolver; this.scope = scope ?? new CssScope(); this.browserSupport = this.context.BrowserSupport; }
public static StyleSheet Parse(string text, CssContext context = null) => Parse(new StringReader(text), context);
public static StyleSheet Parse(Stream stream, CssContext context = null) => Parse(new StreamReader(stream), context);
public StyleSheet(CssContext context) : base() { Context = context; }
public StyleSheet(List<CssNode> children, CssContext context) : base(children) { Context = context; }
public static StyleSheet FromFile(FileInfo file, CssContext context = null) { string text; using (var reader = file.OpenText()) { text = reader.ReadToEnd(); } try { return Parse(text, context); } catch (SyntaxException ex) { ex.Location = TextHelper.GetLocation(text, ex.Position); ex.Lines = TextHelper.GetLinesAround(text, ex.Location.Line, 3).ToList(); throw ex; } }