-
Notifications
You must be signed in to change notification settings - Fork 117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A warning when a css resource could not be downloaded & apply styles only to elements within (and itself) the body #395
base: main
Are you sure you want to change the base?
Conversation
…ied 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.
…eption when a resource could not be downloaded.
try | ||
{ | ||
return cssSource.GetCss(); | ||
} | ||
catch (Exception ex) | ||
{ | ||
_warnings.Add(ex.Message); | ||
return string.Empty; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm honestly a bit torn on this change. If your html needs a CSS source and it is not available, aren't we breaking things by ignoring that and silently moving ahead?
@@ -405,7 +417,7 @@ private void RemoveStyleElements(IEnumerable<IElement> cssSourceNodes, bool pres | |||
Selector = selectorParser.ParseSelector(x.Value.Name) | |||
}).Where(x => x.Selector != null).ToList(); | |||
|
|||
foreach (var el in _document.DescendentsAndSelf<IElement>()) | |||
foreach (var el in _document.Body.DescendentsAndSelf<IElement>()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unsure if we create problems by not allowing to target the html
tag? I cannot rule out the use of obscure hacks on the html
element for some email clients is necessary?
Would need some more research to be honest. You could also avoid the style tags on those elements, with body *
?
Let GetCssBlocks add a warning to the list instead of throwing an exception when a resource could not be downloaded.
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.
Maybe there is another way not to match the all selector to the elements above the body, but this was a quick fix for us.