all repos — markup @ 1a659c4aed737afd7a612265c79258417f0fd902

The code we use to render README.your_favorite_markup

lib/github/markup.rb (view raw)

 1require 'rdiscount'
 2require 'redcloth'
 3
 4module GitHub
 5  module Markup
 6    extend self
 7    @@markups = {}
 8
 9    def markups
10      @@markups
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]
27    end
28  end
29end
30
31begin
32  require 'rdiscount'
33  GitHub::Markup.add_markup(/md|mkdn?|markdown/) do |content|
34    Markdown.new(content).to_html
35  end
36rescue LoadError
37  nil
38end
39
40begin
41  require 'redcloth'
42  GitHub::Markup.add_markup(/textile/) do |content|
43    RedCloth.new(content).to_html
44  end
45rescue LoadError
46  nil
47end