FIX: Edge cases with markdown references for InlineUploads.

This commit is contained in:
Guo Xiang Tan
2019-06-13 12:08:01 +08:00
parent 93c552afda
commit 782e583844
2 changed files with 26 additions and 8 deletions
+12 -4
View File
@@ -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