christiaan / InlineStyle

Transform embedded and external stylesheets to style attributes on the HTML tags.
MIT License
139 stars 27 forks source link

prevent escaping mailchimp variables #30

Open vladkucherov opened 10 years ago

vladkucherov commented 10 years ago

Hello there,

it looks like if you use variables inside quotes, they get escaped. for example:

<a href="mailto:*|EMAIL|*">*|EMAIL|*</a>

The result would be:

<a href="mailto:*%7CEMAIL%7C*>test@test.com</a>

Any ideas on how to make it ignore specific chars inside quotes?

christiaan commented 10 years ago

I think this is a DOMDocument problem. Can you reproduce this issue when you load the HTML into DOMDocument and then have it output HTML again?

vladkucherov commented 10 years ago

Yes, this is the case. apparently, DOMDocument tries to "fix" HTML attributes and reformat the data. I couldn't find a way to force him ignore the contents of attribute.

The only solution I found is to run over the output and replace back the escaped data - not good practice...

Also... for those who will get the same issue with Mailchimp / Mandrill, they provide an inliner of there own. just set "inline_css":true to your request.

ambroisemaupate commented 9 years ago

Hi there.

I have the same suggestion using Mailjet variables like [[PERMALINK]] or [[UNSUB_LINK_FR]]. But MailJet is not as smart as MailChimp and does not inline styles for you.

christiaan commented 9 years ago

You could use preg_replace_callback to replace all those instances with unique strings that are not escaped. Then after inlining replace them back.

I've marked it as a feature but I'm not so sure it is within the scope of this project. However I see this is a recurring problem for the intended usecase.

When you do get this working using the suggested substitute replace method described I would be happy to either include or link to your solution.

staceypee commented 3 years ago

Hello! Sorry to inject myself into a years-old conversation. Hoping that someone has since solved this?