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:
parent
51ee49aad2
commit
aba76bace6
3 changed files with 16 additions and 5 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue