From f244650832bfeb37ca11cbd0dc7da1504db5071b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 10 Oct 2013 11:57:36 +0200 Subject: [PATCH] update images:pull_hotlinked rake task to add support for the markdown reference link style --- lib/tasks/images.rake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 - ![alt](http://...) + # Markdown inline - ![alt](http://...) post.raw.gsub!(/!\[([^\]]*)\]\(#{src_for_regexp}\)/) { "![#{$1}](#{upload_urls[src]})" } + # 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