Email-builder / grunt-email-builder

Build Emails from HTML / CSS code in grunt
Other
94 stars 14 forks source link

encodeSpecialChars ignore attribute feature #46

Open boggsey opened 8 years ago

boggsey commented 8 years ago

I ran into a problem recently with encodeSpecialChars, attributes and ExactTarget. I have a Spanish language email that needs to be encoded, so encodeSpecialChars is a big help. Unfortunately for me, encodeSpecialChars encodes the entirety of special characters. This behavior is problematic because it includes ampersands in href attribute values. I didn't think it would be a problem until I ran a few emails that contained multiple &s and anchor links referencing a section within a page. When this email is sent, ExactTarget replaces each url with it's url forwarding tracking magic and some parameters get lost in the sauce. This does not happen when ampersands are not encoded in the href attribute.

I'm thinking that it might make sense to include an ignore attributes or ignore specific attributes option for encodeSpecialChars, because I don't necessarily need to not encode all ampersands. I know this is partly an ExactTarget problem and might be a pretty extreme edge case, but it has become a pretty consistent issue for me. I'm probably going to fork the repo and try to fix it soon. It just depends on how many Spanish emails I have to code. Just wanted to make you aware.

jeremypeter commented 8 years ago

Underneath we use https://github.com/hughsk/special-html. I think the best thing would be to convert the & back to their decoded form using something like grunt-replace and using the pattern:

{
  match: /&/g,
  replacement: '&'
}