##// END OF EJS Templates
Moves attachments parsing after textile parsing so that:...
Jean-Philippe Lang -
r3139:b718d5dec207
parent child
Show More
@@ -402,6 +402,8 module ApplicationHelper
402 end
402 end
403 return '' if text.blank?
403 return '' if text.blank?
404
404
405 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
406
405 only_path = options.delete(:only_path) == false ? false : true
407 only_path = options.delete(:only_path) == false ? false : true
406
408
407 # when using an image link, try to use an attachment, if possible
409 # when using an image link, try to use an attachment, if possible
@@ -409,22 +411,23 module ApplicationHelper
409
411
410 if attachments
412 if attachments
411 attachments = attachments.sort_by(&:created_on).reverse
413 attachments = attachments.sort_by(&:created_on).reverse
412 text = text.gsub(/!((\<|\=|\>)?(\([^\)]+\))?(\[[^\]]+\])?(\{[^\}]+\})?)(\S+\.(bmp|gif|jpg|jpeg|png))!/i) do |m|
414 text.gsub!(/src="([^\/"]+\.(bmp|gif|jpg|jpeg|png))"(\s+alt="([^"]*)")?/i) do |m|
413 style = $1
415 filename, ext, alt, alttext = $1.downcase, $2, $3, $4
414 filename = $6.downcase
416
415 # search for the picture in attachments
417 # search for the picture in attachments
416 if found = attachments.detect { |att| att.filename.downcase == filename }
418 if found = attachments.detect { |att| att.filename.downcase == filename }
417 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
419 image_url = url_for :only_path => only_path, :controller => 'attachments', :action => 'download', :id => found
418 desc = found.description.to_s.gsub(/^([^\(\)]*).*$/, "\\1")
420 desc = found.description.to_s.gsub('"', '')
419 alt = desc.blank? ? nil : "(#{desc})"
421 if !desc.blank? && alttext.blank?
420 "!#{style}#{image_url}#{alt}!"
422 alt = " title=\"#{desc}\" alt=\"#{desc}\""
423 end
424 "src=\"#{image_url}\"#{alt}"
421 else
425 else
422 m
426 m
423 end
427 end
424 end
428 end
425 end
429 end
426
430
427 text = Redmine::WikiFormatting.to_html(Setting.text_formatting, text) { |macro, args| exec_macro(macro, obj, args) }
428
431
429 # different methods for formatting wiki links
432 # different methods for formatting wiki links
430 case options[:wiki_links]
433 case options[:wiki_links]
General Comments 0
You need to be logged in to leave comments. Login now