Skip to content

Commit

Permalink
macro対応
Browse files Browse the repository at this point in the history
  • Loading branch information
donza committed Sep 17, 2009
1 parent d45ef64 commit e4354b3
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion lib/redmine_markdown_extra_formatter/wiki_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,55 @@

module RedmineMarkdownExtraFormatter
class WikiFormatter


def initialize(text)
@text = text
end

def to_html(&block)
BlueFeather.parse(@text.gsub(/\[(.+)\]\((https?:\/\/.+)\)/, '[\1](/redirect/\2)'))

@macros_runner = block

parsedText = BlueFeather.parse(@text.gsub(/\[(.+)\]\((https?:\/\/.+)\)/, '[\1](/redirect/\2)'))

inline_macros(parsedText)

rescue => e
return("<pre>problem parsing wiki text: #{e.message}\n"+
"original text: \n"+
@text+
"</pre>")
end

MACROS_RE = /
(!)? # escaping
(
\{\{ # opening tag
([\w]+) # macro name
(\(([^\}]*)\))? # optional arguments
\}\} # closing tag
)
/x

def inline_macros(text)

text.gsub!(MACROS_RE) do
esc, all, macro = $1, $2, $3.downcase
args = ($5 || '').split(',').each(&:strip)
if esc.nil?
begin
@macros_runner.call(macro, args)
rescue => e
"<div class=\"flash error\">Error executing the <strong>#{macro}</strong> macro (#{e})</div>"
end || all
else
all
end
end

text
end

end
end

0 comments on commit e4354b3

Please sign in to comment.