RE: Wiki External Filter plugin released ยป wiki-external-filter-textile-workaround-2010-07-20.patch
| lib/redmine/wiki_formatting/textile/formatter.rb | ||
|---|---|---|
|
require 'redcloth3'
|
||
|
require 'coderay'
|
||
|
require 'digest/md5'
|
||
|
module Redmine
|
||
|
module WikiFormatting
|
||
| ... | ... | |
|
def to_html(*rules, &block)
|
||
|
@toc = []
|
||
|
@macros_runner = block
|
||
|
preprocess_inline_macros self # FIXME: silly to edit self
|
||
|
super(*RULES).to_s
|
||
|
end
|
||
|
|
||
| ... | ... | |
|
(
|
||
|
\{\{ # opening tag
|
||
|
([\w]+) # macro name
|
||
|
(\(([^\}]*)\))? # optional arguments
|
||
|
(\((.*?)\))? # optional arguments
|
||
|
\}\} # closing tag
|
||
|
)
|
||
|
/x unless const_defined?(:MACROS_RE)
|
||
|
/xm unless const_defined?(:MACROS_RE)
|
||
|
|
||
|
# grab raw text for wiki_external_filter macro
|
||
|
def preprocess_inline_macros(text)
|
||
|
@inline_macros_grabbed = {}
|
||
|
text.gsub!(MACROS_RE) do |s|
|
||
|
esc, all, macro = $1, $2, $3.downcase
|
||
|
if esc.nil? and (WikiExternalFilterHelper.has_macro macro rescue false)
|
||
|
args = $5
|
||
|
key = Digest::MD5.hexdigest("#{macro}:#{args}")
|
||
|
@inline_macros_grabbed[key] = {:macro => macro, :args => args}
|
||
|
"{{_inline_macros_grabbed(#{key})}}"
|
||
|
else
|
||
|
s
|
||
|
end
|
||
|
end
|
||
|
end
|
||
|
def inline_macros(text)
|
||
|
text.gsub!(MACROS_RE) do
|
||
|
esc, all, macro = $1, $2, $3.downcase
|
||
|
args = ($5 || '').split(',').each(&:strip)
|
||
|
args = ($5 || '').split(',').map(&:strip)
|
||
|
if macro == '_inline_macros_grabbed' and @inline_macros_grabbed.member? args.first
|
||
|
macro, args = @inline_macros_grabbed[args.first].values_at(:macro, :args)
|
||
|
end
|
||
|
if esc.nil?
|
||
|
begin
|
||
|
@macros_runner.call(macro, args)
|
||
| ... | ... | |
|
all
|
||
|
end
|
||
|
end
|
||
|
ensure
|
||
|
@inline_macros_grabbed.clear
|
||
|
end
|
||
|
|
||
|
AUTO_LINK_RE = %r{
|
||