all repos — markup @ 768130a25a0fb9ed979887ad039b796237397f99

The code we use to render README.your_favorite_markup

lib/github/markup.rb (view raw)

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