mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FIX: format posts for embedded comments as we do for emails
This commit is contained in:
@@ -343,29 +343,36 @@ module PrettyText
|
||||
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.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.convert_vimeo_iframes(doc)
|
||||
doc.css("iframe[src*='player.vimeo.com']").each do |iframe|
|
||||
vimeo_id = iframe['src'].split('/').last
|
||||
iframe.replace "<p><a href='https://vimeo.com/#{vimeo_id}'>https://vimeo.com/#{vimeo_id}</a></p>"
|
||||
end
|
||||
end
|
||||
|
||||
def self.format_for_email(html, post = nil)
|
||||
doc = Nokogiri::HTML.fragment(html)
|
||||
DiscourseEvent.trigger(:reduce_cooked, doc, post)
|
||||
strip_image_wrapping(doc)
|
||||
convert_vimeo_iframes(doc)
|
||||
make_all_links_absolute(doc)
|
||||
doc.to_html
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user