From f52599f85d7771bf16357addaa2b9c7f4945021a Mon Sep 17 00:00:00 2001 From: godie Date: Mon, 1 Dec 2025 20:27:43 -0500 Subject: [PATCH] fix styles, conditional styles check if email has title meta --- app/helpers/messages_helper.rb | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/helpers/messages_helper.rb b/app/helpers/messages_helper.rb index 32e1be397..09602d6d2 100755 --- a/app/helpers/messages_helper.rb +++ b/app/helpers/messages_helper.rb @@ -10,16 +10,23 @@ def render_email_content(message) # Parse the HTML doc = Nokogiri::HTML.fragment(html_content) - # Remove the trix-content wrapper div if present (do this first) - trix_div = doc.at_css('div.trix-content') - if trix_div - # Replace the trix-content div with its children - trix_div.replace(trix_div.children.to_html) - # Re-parse after removing trix wrapper - doc = Nokogiri::HTML.fragment(doc.to_html) + # Detect if this is a Revolvapp email template by checking for characteristic tags + # Revolvapp emails have meta, style, title, or link tags + is_revolvapp_email = doc.css('meta, style, title, link').any? + + # Only remove the trix-content wrapper for Revolvapp emails + # Regular Trix editor content needs the wrapper for proper CSS styling + if is_revolvapp_email + trix_div = doc.at_css('div.trix-content') + if trix_div + # Replace the trix-content div with its children + trix_div.replace(trix_div.children.to_html) + # Re-parse after removing trix wrapper + doc = Nokogiri::HTML.fragment(doc.to_html) + end end - # Remove meta tags, style tags, title, and link tags + # Remove meta tags, style tags, title, and link tags (only present in Revolvapp emails) doc.css('meta').remove doc.css('style').remove doc.css('title').remove @@ -29,9 +36,11 @@ def render_email_content(message) result = doc.to_html # Remove leading text nodes that appear before the first HTML tag - # This handles orphaned text like "My Email" from the title tag - # Match any text at the beginning that comes before the first < character - result = result.sub(/\A([^<]*?)(<)/, '\2') + # This handles orphaned text like "My Email" from the title tag in Revolvapp emails + # Only do this for Revolvapp emails to avoid affecting regular content + if is_revolvapp_email + result = result.sub(/\A([^<]*?)(<)/, '\2') + end result.html_safe end