AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.8.7" />

 CssStyleFormatter

public sealed class CssStyleFormatter : IStyleFormatter
Represents the standard CSS3 style formatter.
using System; using System.Collections.Generic; using System.Text; namespace AngleSharp.Css { public sealed class CssStyleFormatter : IStyleFormatter { public static readonly IStyleFormatter Instance = new CssStyleFormatter(); string IStyleFormatter.Sheet(IEnumerable<IStyleFormattable> rules) { List<string> list = new List<string>(); foreach (IStyleFormattable rule in rules) { list.Add(rule.ToCss(this)); } return string.Join(Environment.NewLine, list); } string IStyleFormatter.Block(IEnumerable<IStyleFormattable> rules) { StringBuilder stringBuilder = Pool.NewStringBuilder().Append('{'); foreach (IStyleFormattable rule in rules) { stringBuilder.Append(' ').Append(rule.ToCss(this)); } return stringBuilder.Append(' ').Append('}').ToPool(); } string IStyleFormatter.Declaration(string name, string value, bool important) { string str = value + (important ? " !important" : string.Empty); return name + ": " + str + ";"; } string IStyleFormatter.Medium(bool exclusive, bool inverse, string type, string[] constraints) { string str = exclusive ? "only " : (inverse ? "not " : string.Empty); if (constraints.Length != 0) { string text = string.Join(" and ", constraints); if (string.IsNullOrEmpty(type)) return str + text; return str + type + " and " + text; } return str + (type ?? string.Empty); } string IStyleFormatter.Constraint(string name, string value) { string str = (value != null) ? (": " + value) : string.Empty; return "(" + name + str + ")"; } string IStyleFormatter.Rule(string name, string value) { return name + " " + value + ";"; } string IStyleFormatter.Rule(string name, string prelude, string rules) { string str = string.IsNullOrEmpty(prelude) ? string.Empty : (prelude + " "); return name + " " + str + rules; } string IStyleFormatter.Style(string selector, string rules) { string str = string.IsNullOrEmpty(rules) ? " {" : " { "; return selector + str + rules + " }"; } string IStyleFormatter.Declarations(IEnumerable<string> declarations) { return string.Join(" ", declarations); } } }