diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 8deed90..a3509b9 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -165,16 +165,16 @@ module ApplicationHelper
# when using an image link, try to use an attachment, if possible
attachments = options[:attachments]
if attachments
- text = text.gsub(/!([<>=]*)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
- align = $1
- filename = $2
+ text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m|
+ style = $1
+ filename = $6
rf = Regexp.new(filename, Regexp::IGNORECASE)
# search for the picture in attachments
if found = attachments.detect { |att| att.filename =~ rf }
image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id
- "!#{align}#{image_url}!"
+ "!#{style}#{image_url}!"
else
- "!#{align}#{filename}!"
+ "!#{style}#{filename}!"
end
end
end
diff --git a/lib/redmine/wiki_formatting.rb b/lib/redmine/wiki_formatting.rb
index 4aebe9a..f7fa803 100644
--- a/lib/redmine/wiki_formatting.rb
+++ b/lib/redmine/wiki_formatting.rb
@@ -25,7 +25,8 @@ module Redmine
class TextileFormatter < RedCloth
- RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros]
+ # auto_link rule after textile rules so that it doesn't break !image_url! tags
+ RULES = [:textile, :inline_auto_link, :inline_auto_mailto, :inline_toc, :inline_macros]
def initialize(*args)
super
diff --git a/test/unit/helpers/application_helper_test.rb b/test/unit/helpers/application_helper_test.rb
index 06446d1..2af6c55 100644
--- a/test/unit/helpers/application_helper_test.rb
+++ b/test/unit/helpers/application_helper_test.rb
@@ -44,12 +44,18 @@ class ApplicationHelperTest < HelperTestCase
textilizable('test@foo.bar')
end
- def test_textile_tags
+ def test_inline_images
to_test = {
- # inline images
'!http://foo.bar/image.jpg!' => '',
'floating !>http://foo.bar/image.jpg!' => 'floating
#{result}
", textilizable(text) } + end + + def test_textile_external_links + to_test = { 'This is a "link":http://foo.bar' => 'This is a link', 'This is an intern "link":/foo/bar' => 'This is an intern link', '"link (Link title)":http://foo.bar' => 'link'