BetterCms.Module.Pages.Helpers.CssHelper.PrefixCssSelectors C# (CSharp) Method

PrefixCssSelectors() public static method

Add the prefix to CSS selector.
public static PrefixCssSelectors ( string css, string selectorPrefix ) : string
css string The CSS.
selectorPrefix string The selector prefix.
return string
        public static string PrefixCssSelectors(string css, string selectorPrefix)
        {
            if (string.IsNullOrWhiteSpace(css))
            {
                return null;
            }

            // Strip CSS Comments:
            var cssWithoutComments = Regex.Replace(css, "/\\*.+?\\*/", string.Empty, RegexOptions.Singleline);

            var rules = Regex.Split(cssWithoutComments, "(?<=\\}).", RegexOptions.Singleline);
            var cssRules = new List<string>();
            var prefix = selectorPrefix + " ";

            foreach (var rule in rules.Where(s => !string.IsNullOrWhiteSpace(s)))
            {
                cssRules.Add(PrefixCssSelectorsForSingleRule(prefix, rule));
            }

            return string.Join(Environment.NewLine, cssRules.ToArray());
        }