@@ -165,16 +165,16 module ApplicationHelper | |||
|
165 | 165 | # when using an image link, try to use an attachment, if possible |
|
166 | 166 | attachments = options[:attachments] |
|
167 | 167 | if attachments |
|
168 |
text = text.gsub(/!( |
|
|
169 |
|
|
|
170 |
filename = $ |
|
|
168 | text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(gif|jpg|jpeg|png))!/) do |m| | |
|
169 | style = $1 | |
|
170 | filename = $6 | |
|
171 | 171 | rf = Regexp.new(filename, Regexp::IGNORECASE) |
|
172 | 172 | # search for the picture in attachments |
|
173 | 173 | if found = attachments.detect { |att| att.filename =~ rf } |
|
174 | 174 | image_url = url_for :controller => 'attachments', :action => 'download', :id => found.id |
|
175 |
"!#{ |
|
|
175 | "!#{style}#{image_url}!" | |
|
176 | 176 | else |
|
177 |
"!#{ |
|
|
177 | "!#{style}#{filename}!" | |
|
178 | 178 | end |
|
179 | 179 | end |
|
180 | 180 | end |
@@ -25,7 +25,8 module Redmine | |||
|
25 | 25 | |
|
26 | 26 | class TextileFormatter < RedCloth |
|
27 | 27 | |
|
28 | RULES = [:inline_auto_link, :inline_auto_mailto, :textile, :inline_toc, :inline_macros] | |
|
28 | # auto_link rule after textile rules so that it doesn't break !image_url! tags | |
|
29 | RULES = [:textile, :inline_auto_link, :inline_auto_mailto, :inline_toc, :inline_macros] | |
|
29 | 30 | |
|
30 | 31 | def initialize(*args) |
|
31 | 32 | super |
@@ -44,12 +44,18 class ApplicationHelperTest < HelperTestCase | |||
|
44 | 44 | textilizable('test@foo.bar') |
|
45 | 45 | end |
|
46 | 46 | |
|
47 |
def test_ |
|
|
47 | def test_inline_images | |
|
48 | 48 | to_test = { |
|
49 | # inline images | |
|
50 | 49 | '!http://foo.bar/image.jpg!' => '<img src="http://foo.bar/image.jpg" alt="" />', |
|
51 | 50 | 'floating !>http://foo.bar/image.jpg!' => 'floating <div style="float:right"><img src="http://foo.bar/image.jpg" alt="" /></div>', |
|
52 | # textile links | |
|
51 | 'with class !(some-class)http://foo.bar/image.jpg!' => 'with class <img src="http://foo.bar/image.jpg" class="some-class" alt="" />', | |
|
52 | 'with style !{width:100px;height100px}http://foo.bar/image.jpg!' => 'with style <img src="http://foo.bar/image.jpg" style="width:100px;height100px;" alt="" />', | |
|
53 | } | |
|
54 | to_test.each { |text, result| assert_equal "<p>#{result}</p>", textilizable(text) } | |
|
55 | end | |
|
56 | ||
|
57 | def test_textile_external_links | |
|
58 | to_test = { | |
|
53 | 59 | 'This is a "link":http://foo.bar' => 'This is a <a href="http://foo.bar" class="external">link</a>', |
|
54 | 60 | 'This is an intern "link":/foo/bar' => 'This is an intern <a href="/foo/bar">link</a>', |
|
55 | 61 | '"link (Link title)":http://foo.bar' => '<a href="http://foo.bar" title="Link title" class="external">link</a>' |
General Comments 0
You need to be logged in to leave comments.
Login now