CssToInlineStyles icon indicating copy to clipboard operation
CssToInlineStyles copied to clipboard

Inlining inside conditional comments

Open Stadly opened this issue 8 years ago • 5 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.

Stadly avatar Apr 06 '16 08:04 Stadly

I understand that this will be difficult to implement in a reliable way. But here is a related question, just in case.

Stadly avatar Sep 05 '16 13:09 Stadly

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 avatar Jan 17 '17 10:01 PreVaDu

@PreVaDu Are you using the latest version of CssToInlineStyles? This should already be fixed by PR https://github.com/tijsverkoyen/CssToInlineStyles/pull/164.

Stadly avatar Jan 17 '17 10:01 Stadly

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.

PreVaDu avatar Jan 17 '17 10:01 PreVaDu

Any chance this can get fixed? Still unable to add styles for classes inside comments.

virgofx avatar Feb 19 '18 21:02 virgofx