If a <style> tag is included in the HTML, the style tag gets removed, and the CSS is rendered directly in the view. I believe we can remove the <style> tag from the email entirely.
Screenshot

Suggested code
module RailsMail
module EmailsHelper
def prepare_email_html(raw_html)
doc = Nokogiri::HTML::DocumentFragment.parse(raw_html)
# Remove all style tags and their content
doc.css('style').remove
doc.css("a[href]").each do |a|
a.set_attribute("target", "_blank")
a.set_attribute("rel", "noopener noreferrer")
a.set_attribute("data-turbo", "false")
end
sanitize(doc.to_html,
tags: ActionView::Base.sanitized_allowed_tags + [ "table", "tbody", "tr", "td" ],
attributes: ActionView::Base.sanitized_allowed_attributes + [ "style", "target", "data-turbo" ])
end
end
end
I think we can remove the embedded <style> tag for now, since in most cases only inline styles are supported.
Let me know what you think @synth
If a <style> tag is included in the HTML, the style tag gets removed, and the CSS is rendered directly in the view. I believe we can remove the <style> tag from the email entirely.
Screenshot
Suggested code
I think we can remove the embedded <style> tag for now, since in most cases only inline styles are supported.
Let me know what you think @synth