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

Inlining inside conditional comments #133

Open
Stadly opened this issue Apr 6, 2016 · 5 comments
Open

Inlining inside conditional comments #133

Stadly opened this issue Apr 6, 2016 · 5 comments

Comments

@Stadly
Copy link
Contributor

Stadly commented Apr 6, 2016

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
Copy link
Contributor Author

Stadly commented Sep 5, 2016

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

@PreVaDu
Copy link

PreVaDu commented Jan 17, 2017

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.

@Stadly
Copy link
Contributor Author

Stadly commented Jan 17, 2017

@PreVaDu Are you using the latest version of CssToInlineStyles? This should already be fixed by PR #164.

@PreVaDu
Copy link

PreVaDu commented Jan 17, 2017

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.

@virgofx
Copy link

virgofx commented Feb 19, 2018

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

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

3 participants