Skip to content
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

Disable inlinling of certail style tags #229

Open
e1himself opened this issue Jul 13, 2022 · 1 comment
Open

Disable inlinling of certail style tags #229

e1himself opened this issue Jul 13, 2022 · 1 comment

Comments

@e1himself
Copy link

e1himself commented Jul 13, 2022

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 👍

@dweidner
Copy link

I was looking for the same functionality.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants