README.md (view raw)
1GitHub Markup
2=============
3
4We use this library on GitHub when rendering your README or any other
5rich text file.
6
7Markups
8-------
9
10The following markups are supported. The dependencies listed are required if
11you wish to run the library.
12
13* [.markdown](http://daringfireball.net/projects/markdown/) -- `gem install markdown`
14* [.textile](http://www.textism.com/tools/textile/) -- `gem install RedCloth`
15* [.rdoc](http://rdoc.sourceforge.net/)
16* [.org](http://orgmode.org/) -- `gem install org-mode`
17* [.rst](http://docutils.sourceforge.net/rst.html) -- `easy_install docutils`
18* [.asciidoc](http://www.methods.co.nz/asciidoc/) -- `brew install asciidoc`
19* [.pod](http://search.cpan.org/dist/perl/pod/perlpod.pod) -- `Pod::Simple::HTML` *should come with Perl*
20* .1 - Requires [`groff`](http://www.gnu.org/software/groff/)
21
22
23Contributing
24------------
25
26Want to contribute? Great! There are two ways to add markups.
27
28
29### Commands
30
31If your markup is in a language other than Ruby, drop a translator
32script in `lib/github/commands` which accepts input on STDIN and
33returns HTML on STDOUT. See [rest2html][r2h] for an example.
34
35Once your script is in place, edit `lib/github/markups.rb` and tell
36GitHub Markup about it. Again we look to [rest2html][r2hc] for
37guidance:
38
39 command(:rest2html, /re?st(.txt)?/)
40
41Here we're telling GitHub Markup of the existence of a `rest2html`
42command which should be used for any file ending in `rest`,
43`rst`, `rest.txt` or `rst.txt`. Any regular expression will do.
44
45Finally add your tests. Create a `README.extension` in `test/markups`
46along with a `README.extension.html`. As you may imagine, the
47`README.extension` should be your known input and the
48`README.extension.html` should be the desired output.
49
50Now run the tests: `rake`
51
52If nothing complains, congratulations!
53
54
55### Classes
56
57If your markup can be translated using a Ruby library, that's
58great. Check out Check `lib/github/markups.rb` for some
59examples. Let's look at Markdown:
60
61 markup(:markdown, /md|mkdn?|markdown/) do |content|
62 Markdown.new(content).to_html
63 end
64
65We give the `markup` method three bits of information: the name of the
66file to `require`, a regular expression for extensions to match, and a
67block to run with unformatted markup which should return HTML.
68
69If you need to monkeypatch a RubyGem or something, check out the
70included RDoc example.
71
72Tests should be added in the same manner as described under the
73`Commands` section.
74
75
76Installation
77-----------
78
79 gem install github-markup
80
81
82Usage
83-----
84
85 require 'github/markup'
86 GitHub::Markup.render('README.markdown', "* One\n* Two")
87
88Or, more realistically:
89
90 require 'github/markup'
91 GitHub::Markup.render(file, File.read(file))
92
93
94Testing
95-------
96
97To run the tests:
98
99 $ rake
100
101To add tests see the `Commands` section earlier in this
102README.
103
104
105Contributing
106------------
107
1081. Fork it.
1092. Create a branch (`git checkout -b my_markup`)
1103. Commit your changes (`git commit -am "Added Snarkdown"`)
1114. Push to the branch (`git push origin my_markup`)
1125. Create an [Issue][1] with a link to your branch
1136. Enjoy a refreshing Diet Coke and wait
114
115
116[r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
117[r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
118[1]: http://github.com/github/markup/issues