From b08ce46663736b7aef300089c43d23969b541176 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=20H=C3=B6rchner?= Date: Fri, 2 Feb 2024 15:15:58 +0100 Subject: [PATCH 1/3] With an All (*) selector in the stylesheet, the css rule is also applied to the html element, head element and elements in the head like script, link etc. To avoid this behaviour only the elements from the body (and itself) are selected to be matched. --- PreMailer.Net/PreMailer.Net/PreMailer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreMailer.Net/PreMailer.Net/PreMailer.cs b/PreMailer.Net/PreMailer.Net/PreMailer.cs index 5621249f..10a8eb0e 100644 --- a/PreMailer.Net/PreMailer.Net/PreMailer.cs +++ b/PreMailer.Net/PreMailer.Net/PreMailer.cs @@ -405,7 +405,7 @@ private Dictionary> FindElementsWithStyles( Selector = selectorParser.ParseSelector(x.Value.Name) }).Where(x => x.Selector != null).ToList(); - foreach (var el in _document.DescendentsAndSelf()) + foreach (var el in _document.Body.DescendentsAndSelf()) { foreach (var style in styles) { From d6ebdecbf229445013a6465adb2dd4ba91b47202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=20H=C3=B6rchner?= Date: Fri, 2 Feb 2024 15:17:00 +0100 Subject: [PATCH 2/3] Let GetCssBlocks add a warning to the list instead of throwing an exception when a resource could not be downloaded. --- PreMailer.Net/PreMailer.Net/PreMailer.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PreMailer.Net/PreMailer.Net/PreMailer.cs b/PreMailer.Net/PreMailer.Net/PreMailer.cs index 10a8eb0e..debf6162 100644 --- a/PreMailer.Net/PreMailer.Net/PreMailer.cs +++ b/PreMailer.Net/PreMailer.Net/PreMailer.cs @@ -247,7 +247,19 @@ private bool DomainMatch(string domain, string url) /// private IEnumerable GetCssBlocks(IEnumerable cssSources) { - return cssSources.Select(styleSource => styleSource.GetCss()).ToList(); + return cssSources.Select(GetCssBlock).ToList(); + } + private string GetCssBlock(ICssSource cssSource) + { + try + { + return cssSource.GetCss(); + } + catch (Exception ex) + { + _warnings.Add(ex.Message); + return string.Empty; + } } private void RemoveCssComments(IEnumerable cssSourceNodes) From 4e4ebe22eb52ea655723c8a23c0dd745f84496eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20H=C3=B8st=20Normark?= Date: Thu, 23 Jan 2025 13:02:25 +0100 Subject: [PATCH 3/3] Update PreMailer.Net/PreMailer.Net/PreMailer.cs --- PreMailer.Net/PreMailer.Net/PreMailer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PreMailer.Net/PreMailer.Net/PreMailer.cs b/PreMailer.Net/PreMailer.Net/PreMailer.cs index debf6162..4fe4a34e 100644 --- a/PreMailer.Net/PreMailer.Net/PreMailer.cs +++ b/PreMailer.Net/PreMailer.Net/PreMailer.cs @@ -417,7 +417,7 @@ private Dictionary> FindElementsWithStyles( Selector = selectorParser.ParseSelector(x.Value.Name) }).Where(x => x.Selector != null).ToList(); - foreach (var el in _document.Body.DescendentsAndSelf()) + foreach (var el in _document.DescendentsAndSelf()) { foreach (var style in styles) {