CssToInlineStyles
CssToInlineStyles copied to clipboard
Disable inlinling of certail style tags
Hi!
I'm working on a problem with certain versions of Outlook email client, and came to a solution where I need to apply styles to every email client, except Microsoft Outlook.
There's a conditional comment that can do that:
<!--[if !mso]><!-->
<style>...</style>
<!--<![endif]-->
But the problem is that it's being inlined, as it's a valid non-commented <style>
attribute.
I've been thinking that having a way to disable inlining of styles from a specific style attribute could solve this. For example, the regular expression in Processor::getCssFromStyleTags()
could ignore style tags that have do-not-inline
attribute:
https://github.com/tijsverkoyen/CssToInlineStyles/blob/master/src/Css/Processor.php#L38-L39
$htmlNoComments = preg_replace('|<!--.*?-->|s', '', $html);
+ $htmlNoComments = preg_replace('|<style(?:.*\sdo-not-inline\s?.*)?>(.*)</style>|s', '', $htmlNoComments);
preg_match_all('|<style(?:\s.*)?>(.*)</style>|isU', $htmlNoComments, $matches);
I can file a PR if you agree it's a good addition.
Anyway, thank you for your great work! This package is helping us a lot with rendering emails :+1: