Send Trix HTML to email
I am using figure tag as attachment for below functionality.
- Image
- Video
- Mentioning using tribute.js
I am storing the trix html directly to mysql db and at same time we are sending the same content to mail. but mail formating is not coming good as its not taking attachment properly. also, I have lots of css to make the editor content good.
As, as per my exploration basecamp is not sending figure tag over mail but its showing in in trix editor.
is there any way to convert trix editor html to normal span format html,
@sstephenson @javan , Please respond.
- Trix version: Latest
- Browser name and version: Chrome Version 73.0.3683.103 (Official Build) (64-bit)
- Operating system: OSX
@Immortalpk just handle this with server-side code, it's what we do in our product. We've got no issue with sending emails w/ images using HTML generated via Trix.
If I am inspecting basecamp mail. its creating different structure while comparing it with stored trix HTML.
Do, I have to add handler to convert trix HTML to pure HTML ?
I don’t think this is really relevant to the Trix project itself, unless someone wants to contribute documentation on the topic. As @jessehanley said, the best solution here is probably to do some processing of the HTML server-side before sending the email to convert to email-friendly styling.
This issue has been automatically marked as stale after 90 days of inactivity. It will be closed if no further activity occurs.
Hi! How did you solve this? @Immortalpk
Hi! How did you solve this? @Immortalpk
Assuming you save the content using has_rich_text :content in the Post model
# somewhere call SomeMailer.with(post_id: 123).some_email_action.deliver
# then in SomeMailer
def some_email_action
dirty_content = Post.find(params[:post_id]).content.body.to_html
clean_content = clean(dirty_content)
mail(to: '[email protected]', from: '[email protected]', body: clean_content, content_type: 'text/html')
end
def clean(dirty_content)
doc = Nokogiri::HTML(dirty_content)
doc.css('action-text-attachment').each do |attachment|
img = doc.create_element 'img'
img['src'] = "https://domain.com#{attachment['url']}"
attachment.replace img
end
doc.to_s
end
I had the same issue in Trix I would have a figure element with a img tag inside but once processed it becomes an active-storage-attachment. the fix was to call .to_trix_html on the ActionText::Content