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 rdiscount`
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-ruby`
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`
20 comes with Perl >= 5.10. Lower versions should install Pod::Simple from CPAN.
21* .1 - Requires [`groff`](http://www.gnu.org/software/groff/)
22
23
24Contributing
25------------
26
27Want to contribute? Great! There are two ways to add markups.
28
29
30### Commands
31
32If your markup is in a language other than Ruby, drop a translator
33script in `lib/github/commands` which accepts input on STDIN and
34returns HTML on STDOUT. See [rest2html][r2h] for an example.
35
36Once your script is in place, edit `lib/github/markups.rb` and tell
37GitHub Markup about it. Again we look to [rest2html][r2hc] for
38guidance:
39
40 command(:rest2html, /re?st(.txt)?/)
41
42Here we're telling GitHub Markup of the existence of a `rest2html`
43command which should be used for any file ending in `rest`,
44`rst`, `rest.txt` or `rst.txt`. Any regular expression will do.
45
46Finally add your tests. Create a `README.extension` in `test/markups`
47along with a `README.extension.html`. As you may imagine, the
48`README.extension` should be your known input and the
49`README.extension.html` should be the desired output.
50
51Now run the tests: `rake`
52
53If nothing complains, congratulations!
54
55
56### Classes
57
58If your markup can be translated using a Ruby library, that's
59great. Check out Check `lib/github/markups.rb` for some
60examples. Let's look at Markdown:
61
62 markup(:markdown, /md|mkdn?|markdown/) do |content|
63 Markdown.new(content).to_html
64 end
65
66We give the `markup` method three bits of information: the name of the
67file to `require`, a regular expression for extensions to match, and a
68block to run with unformatted markup which should return HTML.
69
70If you need to monkeypatch a RubyGem or something, check out the
71included RDoc example.
72
73Tests should be added in the same manner as described under the
74`Commands` section.
75
76
77Installation
78-----------
79
80 gem install github-markup
81
82
83Usage
84-----
85
86 require 'github/markup'
87 GitHub::Markup.render('README.markdown', "* One\n* Two")
88
89Or, more realistically:
90
91 require 'github/markup'
92 GitHub::Markup.render(file, File.read(file))
93
94
95Testing
96-------
97
98To run the tests:
99
100 $ rake
101
102To add tests see the `Commands` section earlier in this
103README.
104
105
106Contributing
107------------
108
1091. Fork it.
1102. Create a branch (`git checkout -b my_markup`)
1113. Commit your changes (`git commit -am "Added Snarkdown"`)
1124. Push to the branch (`git push origin my_markup`)
1135. Create an [Issue][1] with a link to your branch
1146. Enjoy a refreshing Diet Coke and wait
115
116
117[r2h]: http://github.com/github/markup/tree/master/lib/github/commands/rest2html
118[r2hc]: http://github.com/github/markup/tree/master/lib/github/markups.rb#L13
119[1]: http://github.com/github/markup/issues