CssToInlineStyles
CssToInlineStyles copied to clipboard
Inlining inside conditional comments
Conditional comments don't seem to be supported.
$css = ".container {font-weight: bold;}";
$html = <<<END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div class="container">Some general message</div>
<!--[if mso]><div class="container">You are using Outlook!</div><![endif]-->
</body></html>
END;
$inliner = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($html, $css);
die($inliner->convert());
The above code gives this result:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div class="container" style="font-weight: bold;">Some general message</div>
<!--[if mso]><div class="container">You are using Outlook!</div><![endif]-->
</body></html>
I would like also the html inside the conditional comment to get inline styles:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><body>
<div class="container" style="font-weight: bold;">Some general message</div>
<!--[if mso]><div class="container" style="font-weight: bold;">You are using Outlook!</div><![endif]-->
</body></html>
This would be very useful when having to work around quirks in Outlook.
I understand that this will be difficult to implement in a reliable way. But here is a related question, just in case.
I have the opposite problem. If I use conditional CSS pro mso e.g. li{ text-indent: -1em; }
for list items, it's used for inlining, which couse problems in other mail clients. I have to skip style tag like:
<!--[if gte mso 9]>
<style>
li{ text-indent: -1em; }
</style>
<![endif]-->
I remove it using regex $html = preg_replace('/<!--(.*?)-->/Uis', '', $html);
in function convert()
, but not sure, if it is right solution.
@PreVaDu Are you using the latest version of CssToInlineStyles? This should already be fixed by PR https://github.com/tijsverkoyen/CssToInlineStyles/pull/164.
Yes, I use the last release 2.2.0 - using Composer. This fix is not released yet, but thanks for info, I will use it.
Any chance this can get fixed? Still unable to add styles for classes inside comments.