Patch by Jun NAITOH. git-svn-id: http://svn.redmine.org/redmine/trunk@18307 e93f8b46-1217-0410-a6f0-8f06a7374b81tags/4.1.0
@current_section = 0 if options[:edit_section_links] | @current_section = 0 if options[:edit_section_links] | ||||
parse_sections(text, project, obj, attr, only_path, options) | parse_sections(text, project, obj, attr, only_path, options) | ||||
text = parse_non_pre_blocks(text, obj, macros) do |text| | |||||
text = parse_non_pre_blocks(text, obj, macros, options) do |text| | |||||
[:parse_inline_attachments, :parse_hires_images, :parse_wiki_links, :parse_redmine_links].each do |method_name| | [:parse_inline_attachments, :parse_hires_images, :parse_wiki_links, :parse_redmine_links].each do |method_name| | ||||
send method_name, text, project, obj, attr, only_path, options | send method_name, text, project, obj, attr, only_path, options | ||||
end | end | ||||
text.html_safe | text.html_safe | ||||
end | end | ||||
def parse_non_pre_blocks(text, obj, macros) | |||||
def parse_non_pre_blocks(text, obj, macros, options={}) | |||||
s = StringScanner.new(text) | s = StringScanner.new(text) | ||||
tags = [] | tags = [] | ||||
parsed = +'' | parsed = +'' | ||||
text, full_tag, closing, tag = s[1], s[2], s[3], s[4] | text, full_tag, closing, tag = s[1], s[2], s[3], s[4] | ||||
if tags.empty? | if tags.empty? | ||||
yield text | yield text | ||||
inject_macros(text, obj, macros) if macros.any? | |||||
inject_macros(text, obj, macros, true, options) if macros.any? | |||||
else | else | ||||
inject_macros(text, obj, macros, false) if macros.any? | |||||
inject_macros(text, obj, macros, false, options) if macros.any? | |||||
end | end | ||||
parsed << text | parsed << text | ||||
if tag | if tag | ||||
end | end | ||||
# Executes and replaces macros in text | # Executes and replaces macros in text | ||||
def inject_macros(text, obj, macros, execute=true) | |||||
def inject_macros(text, obj, macros, execute=true, options={}) | |||||
text.gsub!(MACRO_SUB_RE) do | text.gsub!(MACRO_SUB_RE) do | ||||
all, index = $1, $2.to_i | all, index = $1, $2.to_i | ||||
orig = macros.delete(index) | orig = macros.delete(index) | ||||
if execute && orig && orig =~ MACROS_RE | if execute && orig && orig =~ MACROS_RE | ||||
esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip) | esc, all, macro, args, block = $2, $3, $4.downcase, $6.to_s, $7.try(:strip) | ||||
if esc.nil? | if esc.nil? | ||||
h(exec_macro(macro, obj, args, block) || all) | |||||
h(exec_macro(macro, obj, args, block, options) || all) | |||||
else | else | ||||
h(all) | h(all) | ||||
end | end |
Redmine::WikiFormatting::Macros.available_macros.key?(name.to_sym) | Redmine::WikiFormatting::Macros.available_macros.key?(name.to_sym) | ||||
end | end | ||||
def exec_macro(name, obj, args, text) | |||||
def exec_macro(name, obj, args, text, options={}) | |||||
macro_options = Redmine::WikiFormatting::Macros.available_macros[name.to_sym] | macro_options = Redmine::WikiFormatting::Macros.available_macros[name.to_sym] | ||||
return unless macro_options | return unless macro_options | ||||
if options[:inline_attachments] == false | |||||
Redmine::WikiFormatting::Macros.inline_attachments = false | |||||
else | |||||
Redmine::WikiFormatting::Macros.inline_attachments = true | |||||
end | |||||
method_name = "macro_#{name}" | method_name = "macro_#{name}" | ||||
unless macro_options[:parse_args] == false | unless macro_options[:parse_args] == false | ||||
args = args.split(',').map(&:strip) | args = args.split(',').map(&:strip) | ||||
end | end | ||||
@@available_macros = {} | @@available_macros = {} | ||||
@@inline_attachments = true | |||||
mattr_accessor :available_macros | mattr_accessor :available_macros | ||||
mattr_accessor :inline_attachments | |||||
class << self | class << self | ||||
# Plugins can use this method to define new macros: | # Plugins can use this method to define new macros: | ||||
@included_wiki_pages ||= [] | @included_wiki_pages ||= [] | ||||
raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.id) | raise 'Circular inclusion detected' if @included_wiki_pages.include?(page.id) | ||||
@included_wiki_pages << page.id | @included_wiki_pages << page.id | ||||
out = textilizable(page.content, :text, :attachments => page.attachments, :headings => false) | |||||
out = textilizable(page.content, :text, :attachments => page.attachments, :headings => false, :inline_attachments => @@inline_attachments) | |||||
@included_wiki_pages.pop | @included_wiki_pages.pop | ||||
out | out | ||||
end | end | ||||
out = ''.html_safe | out = ''.html_safe | ||||
out << link_to_function(show_label, js, :id => "#{html_id}-show", :class => 'collapsible collapsed') | out << link_to_function(show_label, js, :id => "#{html_id}-show", :class => 'collapsible collapsed') | ||||
out << link_to_function(hide_label, js, :id => "#{html_id}-hide", :class => 'collapsible', :style => 'display:none;') | out << link_to_function(hide_label, js, :id => "#{html_id}-hide", :class => 'collapsible', :style => 'display:none;') | ||||
out << content_tag('div', textilizable(text, :object => obj, :headings => false), :id => html_id, :class => 'collapsed-text', :style => 'display:none;') | |||||
out << content_tag('div', textilizable(text, :object => obj, :headings => false, :inline_attachments => @@inline_attachments), :id => html_id, :class => 'collapsed-text', :style => 'display:none;') | |||||
out | out | ||||
end | end | ||||