mirror of
https://github.com/discourse/discourse.git
synced 2024-12-02 07:36:09 +08: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
|
end
|
||||||
|
|
||||||
def self.match_img(markdown, external_src: false)
|
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]
|
node = Nokogiri::HTML::fragment(match[3].strip).children[0]
|
||||||
src = node.attributes["src"]&.value
|
src = node.attributes["src"]&.value
|
||||||
|
|
||||||
|
@ -245,11 +245,15 @@ class InlineUploads
|
||||||
|
|
||||||
match[3].strip! if !after_html_tag
|
match[3].strip! if !after_html_tag
|
||||||
|
|
||||||
if match[1].nil? || match[1].length < 4
|
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?
|
yield(match[3], src, replacement, $~.offset(0)[0]) if block_given?
|
||||||
else
|
else
|
||||||
yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given?
|
yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given?
|
||||||
end
|
end
|
||||||
|
else
|
||||||
|
yield(match[3], src, match[3].sub(src, PATH_PLACEHOLDER), $~.offset(0)[0]) if block_given?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -325,6 +325,10 @@ RSpec.describe InlineUploads do
|
||||||
<img src="#{upload2.url}" alt="test" width="500" height="500">
|
<img src="#{upload2.url}" alt="test" width="500" height="500">
|
||||||
</a>
|
</a>
|
||||||
MD
|
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
|
end
|
||||||
|
|
||||||
it "should correctly update image sources within anchor or paragraph tags" do
|
it "should correctly update image sources within anchor or paragraph tags" do
|
||||||
|
|
Loading…
Reference in New Issue
Block a user