Ejemplo n.º 1
0
        /// <summary>Scans a CSS style sheet and returns a clean output removing invalid rules or properties.</summary>
        /// <param name="styleSheet">The CSS style sheet to scan.</param>
        /// <returns>A clean CSS style sheet as string.</returns>
        private void ScanStyleSheet(ICssStyleSheet styleSheet)
        {
            var i = 0;

            while (i < styleSheet.Rules.Length)
            {
                ICssRule rule = styleSheet.Rules[i];
                if (!ScanStyleRule(rule))
                {
                    AddError(Constants.ERROR_CSS_RULE_NOTALLOWED, rule.CssText);
                    styleSheet.RemoveAt(i); // Deletes rule in-place (length is dynamic), counter must not be incremented.
                }
                else
                {
                    i++;
                }
            }
        }
Ejemplo 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());
 }