mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 15:54:48 -05:00
FIX: Don't replace img tags within anchor tags with markdown format.
Follow up to 9a25b0d614.
This commit is contained in:
@@ -214,8 +214,8 @@ class InlineUploads
|
||||
end
|
||||
|
||||
def self.match_img(markdown, external_src: false)
|
||||
markdown.scan(/(<(?!img)[^<>]+\/?>)?(\n*)(([ ]*)<img ([^>\n]+)>([ ]*))(\n*)/) do |match|
|
||||
node = Nokogiri::HTML::fragment(match[2].strip).children[0]
|
||||
markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?(\n*)(([ ]*)<img ([^>\n]+)>([ ]*))(\n*)/) do |match|
|
||||
node = Nokogiri::HTML::fragment(match[3].strip).children[0]
|
||||
src = node.attributes["src"]&.value
|
||||
|
||||
if src && (matched_uploads(src).present? || external_src)
|
||||
@@ -228,24 +228,28 @@ class InlineUploads
|
||||
|
||||
spaces_before =
|
||||
if after_html_tag && !match[0].end_with?("/>")
|
||||
(match[3].length > 0 ? match[3] : " ")
|
||||
(match[4].length > 0 ? match[4] : " ")
|
||||
else
|
||||
""
|
||||
end
|
||||
|
||||
replacement = +"#{spaces_before}"
|
||||
|
||||
if after_html_tag && (num_newlines = match[1].length) <= 1
|
||||
if after_html_tag && (num_newlines = match[2].length) <= 1
|
||||
replacement.prepend("\n" * (num_newlines == 0 ? 2 : 1))
|
||||
end
|
||||
|
||||
if after_html_tag && !match[0].end_with?("/>") && (num_newlines = match[6].length) <= 1
|
||||
if after_html_tag && !match[0].end_with?("/>") && (num_newlines = match[7].length) <= 1
|
||||
replacement += ("\n" * (num_newlines == 0 ? 2 : 1))
|
||||
end
|
||||
|
||||
match[2].strip! if !after_html_tag
|
||||
match[3].strip! if !after_html_tag
|
||||
|
||||
yield(match[2], src, replacement, $~.offset(0)[0]) if block_given?
|
||||
if match[1].nil? || match[1].length < 4
|
||||
yield(match[3], src, replacement, $~.offset(0)[0]) if block_given?
|
||||
else
|
||||
yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given?
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user