sighmon / mjml-rails

MJML + ERb/Haml/Slim view template
https://mjml.io
Other
295 stars 64 forks source link

HAML links resulting in inline HTML #81

Open alexlsalt opened 3 years ago

alexlsalt commented 3 years ago

Issue

When using mjml-rails in conjunction with haml, the expected haml behavior of embedding a Ruby link into a line with = resulted in inline HTML instead of a functioning link.

%mj-text
    = "Link your Twitter, Slack, and GitHub accounts today. #{link_to 'Set up integrations >', user_settings_url(@user)}"

Expected behavior

The code above should render a working link, correctly formatted, like this:

Screenshot 2021-03-18 at 16 35 05

Resulting behavior

The HTML appears inline in the corresponding view.

Screenshot 2021-03-18 at 16 35 50


Solutions

We were able to get the links working correctly with either == or ! (examples below). We ultimately went with the bang method (!), but neither option successfully bypassed our Prettier checks.

%mj-text
    == "Link your Twitter, Slack, and GitHub accounts today. #{link_to 'Set up integrations >', user_settings_url(@user)}"

With the bang method, we're able to prevent interpolation escaping. More info here.

%mj-text
    ! Link your Twitter, Slack, and GitHub accounts today. #{link_to 'Set up integrations >', user_settings_url(@user)}

We were able to get everything to work by adding the file in question to our Prettier ignore file.

sighmon commented 2 years ago

@alexlsalt Sorry for the huge delay... did you have any suggestions for changes in mjml-rails? I don't use HAML, so it'd be great if you wanted to put together a PR.