mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 09:26:54 -06:00
FIX: Support carriage return in InlineUploads
.
Follow up to 8deaef3872
.
This commit is contained in:
parent
8deaef3872
commit
7c86f16aa3
@ -214,7 +214,7 @@ class InlineUploads
|
||||
end
|
||||
|
||||
def self.match_img(markdown, external_src: false)
|
||||
markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?(\n*)(([ ]*)<img ([^>\n]+)>([ ]*))(\n*)/) do |match|
|
||||
markdown.scan(/(([ ]*)<(?!img)[^<>]+\/?>)?([\r\n]*)(([ ]*)<img ([^>\n]+)>([ ]*))([\r\n]*)/) do |match|
|
||||
node = Nokogiri::HTML::fragment(match[3].strip).children[0]
|
||||
src = node.attributes["src"]&.value
|
||||
|
||||
@ -245,8 +245,12 @@ class InlineUploads
|
||||
|
||||
match[3].strip! if !after_html_tag
|
||||
|
||||
if match[1].nil? || match[1].length < 4
|
||||
yield(match[3], src, replacement, $~.offset(0)[0]) if block_given?
|
||||
if (match[1].nil? || match[1].length < 4)
|
||||
if (match[4].nil? || match[4].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
|
||||
else
|
||||
yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given?
|
||||
end
|
||||
|
@ -325,6 +325,10 @@ RSpec.describe InlineUploads do
|
||||
<img src="#{upload2.url}" alt="test" width="500" height="500">
|
||||
</a>
|
||||
MD
|
||||
|
||||
md = "<h1></h1>\r\n<a href=\"http://somelink.com\">\r\n <img src=\"#{upload.url}\" alt=\"test\" width=\"500\" height=\"500\">\r\n</a>"
|
||||
|
||||
expect(InlineUploads.process(md)).to eq("<h1></h1>\r\n<a href=\"http://somelink.com\">\r\n <img src=\"#{upload.short_path}\" alt=\"test\" width=\"500\" height=\"500\">\r\n</a>")
|
||||
end
|
||||
|
||||
it "should correctly update image sources within anchor or paragraph tags" do
|
||||
|
Loading…
Reference in New Issue
Block a user