all repos — markup @ 7954cf1e7408bbae15b678e90acd437cfe735194

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 markups
 7      @@markups
 8    end
 9
10    def add_markup(regexp, &block)
11      markups[regexp] = block
12    end
13
14    def renderer(filename)
15      @@markups.each do |key, value|
16        if Regexp.compile("#{key}$") =~ filename
17          return value
18        end
19      end
20    end
21
22    def render(filename, content)
23      renderer(filename)[content] || content
24    end
25  end
26end
27
28begin
29  require 'rdiscount'
30  GitHub::Markup.add_markup(/md|mkdn?|markdown/) do |content|
31    Markdown.new(content).to_html
32  end
33rescue LoadError
34  nil
35end
36
37begin
38  require 'redcloth'
39  GitHub::Markup.add_markup(/textile/) do |content|
40    RedCloth.new(content).to_html
41  end
42rescue LoadError
43  nil
44end