2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-08-21 19:11:18 +08:00

add support to keep img tags when converting to html

This commit is contained in:
Régis Hanol 2017-04-28 22:14:46 +02:00
parent 51ee49aad2
commit aba76bace6
3 changed files with 16 additions and 5 deletions

View file

@ -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 << "![#{title}](#{node["src"]})"
if @opts[:keep_img_tags]
@stack[-1].markdown << node.to_html
else
title = node["alt"].presence || node["title"].presence
@stack[-1].markdown << "![#{title}](#{node["src"]})"
end
end
def visit_a(node)