all repos — markup @ 7ec431ed150d916295474cfa4d6b7d3a6e5a5b61

The code we use to render README.your_favorite_markup

lib/github/markups.rb (view raw)

 1markup(:markdown, /md|mkdn?|mdown|markdown/) do |content|
 2  Markdown.new(content).to_html
 3end
 4
 5markup(:redcloth, /textile/) do |content|
 6  RedCloth.new(content).to_html
 7end
 8
 9markup('github/markup/rdoc', /rdoc/) do |content|
10  GitHub::Markup::RDoc.new(content).to_html
11end
12
13markup('org-ruby', /org/) do |content|
14  Orgmode::Parser.new(content).to_html
15end
16
17command(:rest2html, /re?st(.txt)?/)
18
19command('asciidoc -s --backend=xhtml11 -o - -', /asciidoc/)
20
21# pod2html is nice enough to generate a full-on HTML document for us,
22# so we return the favor by ripping out the good parts.
23#
24# Any block passed to `command` will be handed the command's STDOUT for
25# post processing.
26command("/usr/bin/env perl -MPod::Simple::HTML -e Pod::Simple::HTML::go", /pod/) do |rendered|
27  if rendered =~ /<!-- start doc -->\s*(.+)\s*<!-- end doc -->/mi
28    $1
29  end
30end
31
32#
33# man pages!
34#
35command('groff -t -e -mandoc -Thtml -P -l -P -r -', /\d/) do |rendered, original|
36  # Try to grab the name and section.
37  if original =~ /^.TH (\S+).*?(\d).*$/
38    # Clear out the gunk, "MUSTACHE" => MUSTACHE
39    name, section = $1, $2
40    name.gsub!(/"|'/, '')
41
42    # make MUSTACHE(1)
43    title = "#{name}(#{section})"
44
45    # Classy divs.
46    left = "<div style='float:left'>#{title}</div>"
47    right = "<div style='float:right'>#{title}</div>"
48  end
49
50  if rendered =~ /<body>\s*(.+)\s*<\/body>/mi
51    $1.gsub(/<hr>/, '').gsub(/(<h1.+?h1>)/, "#{left}#{right}\\1")
52  end
53end