Esempio n. 1
0
        /// <summary>Gets the string representation of a CSS style sheet.</summary>
        /// <param name="styleSheet">The CSS style sheet to stringify.</param>
        /// <param name="isMainStyleSheet">If the style sheet is the one scanned,
        /// use <c>false</c> if it is an imported style sheet.</param>
        /// <returns>A CSS style sheet as string.</returns>
        private string StringifyStyleSheet(ICssStyleSheet styleSheet, bool isMainStyleSheet = true)
        {
            var stringWriter = new StringWriter();

            styleSheet.ToCss(stringWriter, new CssStyleFormatter());
            string result = stringWriter.GetStringBuilder().ToString();

            if (policy.EmbedsStyleSheets && isMainStyleSheet)
            {
                foreach (KeyValuePair <string, ICssStyleSheet> imported in ScannedImportedStyleSheets)
                {
                    result = result.Replace(imported.Key, StringifyStyleSheet(imported.Value, isMainStyleSheet: false));
                }
            }

            return(result);
        }
Esempio n. 2
0
 /// <summary>
 /// 过滤规则
 /// </summary>
 /// <param name="cssStyleSheet"></param>
 /// <returns></returns>
 protected virtual string Filters(ICssStyleSheet cssStyleSheet)
 {
     if (cssStyleSheet == null || cssStyleSheet.Rules.Length == 0)
     {
         return(string.Empty);
     }
     for (var i = 0; i < cssStyleSheet.Rules.Length;)
     {
         ICssRule rule = cssStyleSheet.Rules[i];
         if (!Validate(rule))
         {
             cssStyleSheet.RemoveAt(i);
         }
         else
         {
             i++;
         }
     }
     return(cssStyleSheet.ToCss());
 }