peterbe / premailer

Turns CSS blocks into style attributes
https://premailer.io
BSD 3-Clause "New" or "Revised" License
1.06k stars 188 forks source link

Mustache {{ }} syntax in href is broken on transform #248

Closed Samlibardi closed 3 years ago

Samlibardi commented 3 years ago

Hello

Doing a premailer pass causes anchor with template mustaches in href, such as <a href="{{ unsubscribe_link }}">Unsubscribe</a> to be broken like <a href="%7B%7B%20unsubscribe_link%7Ce%20%7D%7D">Unsubscribe</a>

This happens even if I have base_url=None and disable_link_rewrites=True. My guess is it reads the link, checks that disable_link_rewrites is true and writes it back, but it's set to escape chars by default, thus escaping the mustaches.

Reason why it should be able to circumvent this is because it's way more performant to do the premailer transform once than with every e-mail when you're just using the template for simple things such as URLs and names

peterbe commented 3 years ago

It's actually quite expected since <a href="{{ unsubscribe_link }}">Unsubscribe</a> isn't really HTML. You'll have to hack around it. Your goal is noble. The question has come up before as you can imagine. If you want to come up with a hack that's really good we could put it into the core code. For example, there could be an optional option like preserve_handlebar_syntax=True or something. Wanna give it a try?

Quasarman commented 3 years ago

Any workaround for this?