mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
Apply notification styles to mailing list email manually (#4283)
* Apply notification styles to mailing list email manually * Fix failing spec
This commit is contained in:
committed by
Arpit Jalan
parent
0ed4d3d313
commit
7a6bc3f1d7
@@ -394,16 +394,31 @@ JS
|
||||
fragment.to_html
|
||||
end
|
||||
|
||||
# Given a Nokogiri doc, convert all links to absolute
|
||||
def self.make_all_links_absolute(doc)
|
||||
site_uri = nil
|
||||
doc.css("a").each do |link|
|
||||
href = link["href"].to_s
|
||||
begin
|
||||
uri = URI(href)
|
||||
site_uri ||= URI(Discourse.base_url)
|
||||
link["href"] = "#{site_uri}#{link['href']}" unless uri.host.present?
|
||||
rescue URI::InvalidURIError, URI::InvalidComponentError
|
||||
# leave it
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def self.strip_image_wrapping(doc)
|
||||
doc.css(".lightbox-wrapper .meta").remove
|
||||
end
|
||||
|
||||
def self.format_for_email(html, post = nil, style = nil)
|
||||
Email::Styles.new(html, style: style).tap do |doc|
|
||||
DiscourseEvent.trigger(:reduce_cooked, doc, post)
|
||||
doc.make_all_links_absolute
|
||||
doc.send :"format_#{style}" if style
|
||||
end.to_html
|
||||
def self.format_for_email(html, post = nil)
|
||||
doc = Nokogiri::HTML.fragment(html)
|
||||
DiscourseEvent.trigger(:reduce_cooked, doc, post)
|
||||
strip_image_wrapping(doc)
|
||||
make_all_links_absolute(doc)
|
||||
doc.to_html
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
Reference in New Issue
Block a user