diff --git a/lib/tasks/images.rake b/lib/tasks/images.rake
index a6d4e60e222..3dd59330f47 100644
--- a/lib/tasks/images.rake
+++ b/lib/tasks/images.rake
@@ -71,13 +71,15 @@ task "images:pull_hotlinked" => :environment do
# if we have downloaded a file
if upload_urls[src].present?
src_for_regexp = src.gsub("?", "\\?").gsub(".", "\\.").gsub("+", "\\+")
- # there are 4 ways to insert an image in a post
+ # there are 5 ways to insert an image in a post
# HTML tag -
post.raw.gsub!(/src=["']#{src_for_regexp}["']/i, "src='#{upload_urls[src]}'")
# BBCode tag - [img]http://...[/img]
post.raw.gsub!(/\[img\]#{src_for_regexp}\[\/img\]/i, "[img]#{upload_urls[src]}[/img]")
- # Markdown - 
+ # Markdown inline - 
post.raw.gsub!(/!\[([^\]]*)\]\(#{src_for_regexp}\)/) { "" }
+ # Markdown reference - [x]: http://
+ post.raw.gsub!(/\[(\d+)\]: #{src_for_regexp}/) { "[#{$1}]: #{upload_urls[src]}" }
# Direct link
post.raw.gsub!(src, "
")
# mark the post as changed