lib/github/markup.rb (view raw)
1module GitHub
2 module Markup
3 extend self
4 @@markups = {}
5
6 def add_markup(regexp, &block)
7 @@markups[regexp] = block
8 end
9
10 def renderer(filename)
11 @@markups.each do |key, value|
12 if Regexp.compile("#{key}$") =~ filename
13 return value
14 end
15 end
16 end
17
18 def render(filename, content)
19 renderer(filename)[content] || content
20 end
21 end
22end
23
24begin
25 require 'rdiscount'
26 GitHub::Markup.add_markup(/md|mkdn?|markdown/) do |content|
27 Markdown.new(content).to_html
28 end
29rescue LoadError
30 nil
31end
32
33begin
34 require 'redcloth'
35 GitHub::Markup.add_markup(/textile/) do |content|
36 RedCloth.new(content).to_html
37 end
38rescue LoadError
39 nil
40end