Example #1
0
        /// <summary>
        /// This is a duplicate of the instance method CleanUnsupportedSelectors().
        /// <para>It was necessary to make a static method performing the same work to support PrecompileCssString().
        /// The use of the instance method may be converted if they pass in the instance of warnings rather than
        /// reference the instance directly.</para>
        /// </summary>
        /// <param name="selectors"></param>
        /// <param name="warnings"></param>
        /// <returns>A tokenized sorted list of StyleClass instances filtered by those supported.</returns>
        private static SortedList <string, StyleClass> CleanUnsupportedSelectors(SortedList <string, StyleClass> selectors, List <string> warnings)
        {
            var result            = new SortedList <string, StyleClass>();
            var failedSelectors   = new List <StyleClass>();
            var cssSelectorParser = new CssSelectorParser();

            foreach (var selector in selectors)
            {
                if (cssSelectorParser.IsSupportedSelector(selector.Key))
                {
                    result.Add(selector.Key, selector.Value);
                }
                else
                {
                    failedSelectors.Add(selector.Value);
                }
            }

            if (!failedSelectors.Any())
            {
                return(selectors);
            }

            foreach (var failedSelector in failedSelectors)
            {
                warnings.Add(String.Format(
                                 "PreMailer.Net is unable to process the pseudo class/element '{0}' due to a limitation in CsQuery.",
                                 failedSelector.Name));
            }

            return(result);
        }
Example #2
0
 /// <summary>
 /// Constructor for the PreMailer class
 /// </summary>
 /// <param name="html">The HTML input.</param>
 public PreMailer(string html)
 {
     _document          = CQ.CreateDocument(html);
     _warnings          = new List <string>();
     _cssParser         = new CssParser();
     _cssSelectorParser = new CssSelectorParser();
 }
Example #3
0
	    /// <summary>
	    /// Constructor for the PreMailer class
	    /// </summary>
	    /// <param name="html">The HTML input.</param>
        /// <param name="parsingMode">(optional) the mode.</param>
	    public PreMailer(string html,HtmlParsingMode parsingMode)
		{
            _document = CQ.Create(html, parsingMode);
			_warnings = new List<string>();
			_cssParser = new CssParser();
			_cssSelectorParser = new CssSelectorParser();
		}
Example #4
0
		/// <summary>
		/// Constructor for the PreMailer class
		/// </summary>
		/// <param name="html">The HTML input.</param>
		public PreMailer(string html)
		{
			_document = CQ.CreateDocument(html);
			_warnings = new List<string>();
			_cssParser = new CssParser();
			_cssSelectorParser = new CssSelectorParser();
		}
Example #5
0
 /// <summary>
 /// Constructor for the PreMailer class
 /// </summary>
 /// <param name="html">The HTML input.</param>
 /// <param name="parsingMode">(optional) the mode.</param>
 public PreMailer(string html, HtmlParsingMode parsingMode)
 {
     _document          = CQ.Create(html, parsingMode);
     _warnings          = new List <string>();
     _cssParser         = new CssParser();
     _cssSelectorParser = new CssSelectorParser();
 }
Example #6
0
 /// <summary>
 /// Constructor for the PreMailer class
 /// </summary>
 /// <param name="htmlDoc">The HTML document.</param>
 /// <param name="baseUri">Url that all relative urls will be off of</param>
 public PreMailer(IHtmlDocument htmlDoc, Uri baseUri = null)
 {
     _baseUri           = baseUri;
     _document          = htmlDoc;
     _warnings          = new List <string>();
     _cssParser         = new CssParser();
     _cssSelectorParser = new CssSelectorParser();
 }
Example #7
0
 /// <summary>
 /// Constructor for the PreMailer class
 /// </summary>
 /// <param name="html">The HTML input.</param>
 /// <param name="baseUri">Url that all relative urls will be off of</param>
 public PreMailer(string html, Uri baseUri = null)
 {
     _baseUri           = baseUri;
     _document          = new HtmlParser().Parse(html);
     _warnings          = new List <string>();
     _cssParser         = new CssParser();
     _cssSelectorParser = new CssSelectorParser();
 }
Example #8
0
 /// <summary>
 /// Constructor for the PreMailer class
 /// </summary>
 /// <param name="html">The HTML stream.</param>
 /// <param name="baseUri">Url that all relative urls will be off of</param>
 public PreMailer(Stream stream, Uri baseUri = null)
 {
     _baseUri           = baseUri;
     _document          = new HtmlParser().ParseDocument(stream);
     _warnings          = new List <string>();
     _cssParser         = new CssParser();
     _cssSelectorParser = new CssSelectorParser();
 }
Example #9
0
		/// <summary>
		/// Constructor for the PreMailer class
		/// </summary>
		/// <param name="html">The HTML input.</param>
		/// <param name="baseUri">Url that all relative urls will be off of</param>
		public PreMailer(string html, Uri baseUri = null)
		{
			_baseUri = baseUri;
			_document = new HtmlParser().Parse(html);
			_warnings = new List<string>();
			_cssParser = new CssParser();
			_cssSelectorParser = new CssSelectorParser();
		}
Example #10
0
		private PreMailer(string html, bool removeStyleElements = false, string ignoreElements = null)
		{
			_document = CQ.CreateDocument(html);
			_removeStyleElements = removeStyleElements;
			_ignoreElements = ignoreElements;
			_warnings = new List<string>();

			_cssParser = new CssParser();
			_cssSelectorParser = new CssSelectorParser();
		}
        private PreMailer(string html, bool removeStyleElements = false, string ignoreElements = null)
        {
            _document            = CQ.CreateDocument(html);
            _removeStyleElements = removeStyleElements;
            _ignoreElements      = ignoreElements;
            _warnings            = new List <string>();

            _cssParser         = new CssParser();
            _cssSelectorParser = new CssSelectorParser();
        }
Example #12
0
        private PreMailer(string html, bool removeStyleElements = false, string ignoreElements = null, string css = null, bool stripIdAndClassAttributes = false)
        {
            _document                  = CQ.CreateDocument(html);
            _removeStyleElements       = removeStyleElements;
            _stripIdAndClassAttributes = stripIdAndClassAttributes;
            _ignoreElements            = ignoreElements;
            _css      = css;
            _warnings = new List <string>();

            _cssParser         = new CssParser();
            _cssSelectorParser = new CssSelectorParser();
        }
Example #13
0
        /// <summary>
        /// Static method to quickly find the specificity of a single CSS selector.<para/>
        /// Don't use this when parsing a lot of selectors, create an instance of <see cref="CssSelectorParser"/> and use that instead.
        /// </summary>
        /// <param name="selector">CSS Selector</param>
        /// <returns>Specificity score of the given selector.</returns>
        public static int SelectorSpecificity(string selector)
        {
            var instance = new CssSelectorParser();

            return(instance.GetSelectorSpecificity(selector));
        }
		/// <summary>
		/// Static method to quickly find the specificity of a single CSS selector.<para/>
		/// Don't use this when parsing a lot of selectors, create an instance of <see cref="CssSelectorParser"/> and use that instead.
		/// </summary>
		/// <param name="selector">CSS Selector</param>
		/// <returns>Specificity score of the given selector.</returns>
		public static int SelectorSpecificity(string selector)
		{
			var instance = new CssSelectorParser();
			return instance.GetSelectorSpecificity(selector);
		}