all repos — markup @ ef7723962b2220f5fe7bd0e88ed299c60cbda784

The code we use to render README.your_favorite_markup

lib/github/commands/rest2html (view raw)

 1#!/usr/bin/env python
 2
 3"""A small wrapper file for parsing ReST files at GitHub."""
 4
 5__author__ = "Jannis Leidel"
 6__copyright__ = "Copyright (C) 2008 Jannis Leidel"
 7__license__ = "Public Domain"
 8__version__ = "0.1"
 9
10try:
11    import locale
12    locale.setlocale(locale.LC_ALL, '')
13except:
14    pass
15
16import sys
17import codecs
18
19from docutils.core import publish_parts
20from docutils.writers.html4css1 import Writer
21
22SETTINGS = {
23    'cloak_email_addresses': True,
24    'file_insertion_enabled': False,
25    'raw_enabled': False,
26    'strip_comments': True,
27    'doctitle_xform': False,
28    'report_level': 5,
29}
30
31def main():
32    """
33    Parses the given ReST file or the redirected string input and returns the
34    HTML body.
35
36    Usage: rest2html < README.rst
37           rest2html README.rst
38    """
39    try:
40        text = codecs.open(sys.argv[1], 'r', 'utf-8').read()
41    except IOError: # given filename could not be found
42        return ''
43    except IndexError: # no filename given
44        text = sys.stdin.read()
45
46    parts = publish_parts(text, writer=Writer(), settings_overrides=SETTINGS)
47    if 'html_body' in parts:
48        html = parts['html_body']
49        return html.encode('utf-8')
50    return ''
51
52if __name__ == '__main__':
53    print main()