mirror of
https://github.com/discourse/discourse.git
synced 2026-07-29 15:54:48 -05:00
FIX: Edge cases with markdown references for InlineUploads.
This commit is contained in:
@@ -11,6 +11,13 @@ class InlineUploads
|
||||
|
||||
def self.process(markdown, on_missing: nil)
|
||||
markdown = markdown.dup
|
||||
|
||||
match_md_reference(markdown) do |match, src, replacement, index|
|
||||
if upload = Upload.get_from_url(src)
|
||||
markdown = markdown.sub(match, replacement.sub!(PATH_PLACEHOLDER, "__#{upload.sha1}__"))
|
||||
end
|
||||
end
|
||||
|
||||
cooked_fragment = Nokogiri::HTML::fragment(PrettyText.cook(markdown, disable_emojis: true))
|
||||
link_occurences = []
|
||||
|
||||
@@ -40,10 +47,6 @@ class InlineUploads
|
||||
raw_matches << [match, src, replacement, index]
|
||||
end
|
||||
|
||||
match_md_reference(markdown) do |match, src, replacement, index|
|
||||
raw_matches << [match, src, replacement, index]
|
||||
end
|
||||
|
||||
match_img(markdown) do |match, src, replacement, index|
|
||||
raw_matches << [match, src, replacement, index]
|
||||
end
|
||||
@@ -140,6 +143,11 @@ class InlineUploads
|
||||
end
|
||||
end
|
||||
|
||||
markdown.scan(/(__([a-f0-9]{40})__)/) do |match|
|
||||
upload = Upload.find_by(sha1: match[1])
|
||||
markdown = markdown.sub(match[0], upload.short_path)
|
||||
end
|
||||
|
||||
markdown
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user