mirror of
https://github.com/discourse/discourse.git
synced 2025-01-30 05:01:44 +08:00
FIX: Make Email::Styles operate on html documents instead of fragments
`Nokogiri::HTML.fragment` is a huge hack (a comment in the source code admits this). The current behavior of `Email::Styles` is to try to emulate `fragment` using nokogumbo, but it misses some edge cases. In particular, meta tags in a email template don't make it through to the final email. Instead of treating the provided HTML as an indeterminate fragment, this commit makes `Email::Styles` treat the HTML as a complete document. This means that the generated HTML for an email will now always contain top level structure (a doctype, html, head and body tags). This new behavior is behind a hidden site setting for now and defaults off.
This commit is contained in:
parent
cb1b472a0f
commit
1bd8a075d8
|
@ -1104,6 +1104,9 @@ email:
|
||||||
client: true
|
client: true
|
||||||
default: true
|
default: true
|
||||||
hidden: true
|
hidden: true
|
||||||
|
preserve_email_structure_when_styling:
|
||||||
|
default: false
|
||||||
|
hidden: true
|
||||||
|
|
||||||
files:
|
files:
|
||||||
max_image_size_kb:
|
max_image_size_kb:
|
||||||
|
|
|
@ -242,7 +242,12 @@ module Email
|
||||||
strip_classes_and_ids
|
strip_classes_and_ids
|
||||||
replace_relative_urls
|
replace_relative_urls
|
||||||
replace_secure_media_urls
|
replace_secure_media_urls
|
||||||
include_body? ? @fragment.at("body").to_html : @fragment.at("body").children.to_html
|
|
||||||
|
if SiteSetting.preserve_email_structure_when_styling
|
||||||
|
@fragment.to_html
|
||||||
|
else
|
||||||
|
include_body? ? @fragment.at("body").to_html : @fragment.at("body").children.to_html
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def include_body?
|
def include_body?
|
||||||
|
|
Loading…
Reference in New Issue
Block a user