mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
add support to keep img tags when converting to html
This commit is contained in:
@@ -194,7 +194,7 @@ module Email
|
||||
end
|
||||
|
||||
markdown, elided_markdown = if html.present?
|
||||
markdown = HtmlToMarkdown.new(html).to_markdown
|
||||
markdown = HtmlToMarkdown.new(html, keep_img_tags: true).to_markdown
|
||||
markdown = trim_discourse_markers(markdown)
|
||||
EmailReplyTrimmer.trim(markdown, true)
|
||||
end
|
||||
|
||||
@@ -6,7 +6,8 @@ class HtmlToMarkdown
|
||||
def initialize(name, head="", body="", opened=false, markdown=""); super; end
|
||||
end
|
||||
|
||||
def initialize(html)
|
||||
def initialize(html, opts={})
|
||||
@opts = opts || {}
|
||||
@doc = Nokogiri::HTML(html)
|
||||
remove_whitespaces!
|
||||
end
|
||||
@@ -133,8 +134,12 @@ class HtmlToMarkdown
|
||||
end
|
||||
|
||||
def visit_img(node)
|
||||
title = node["alt"].presence || node["title"].presence
|
||||
@stack[-1].markdown << ""
|
||||
if @opts[:keep_img_tags]
|
||||
@stack[-1].markdown << node.to_html
|
||||
else
|
||||
title = node["alt"].presence || node["title"].presence
|
||||
@stack[-1].markdown << ""
|
||||
end
|
||||
end
|
||||
|
||||
def visit_a(node)
|
||||
|
||||
Reference in New Issue
Block a user