all repos — markup @ v0.3.2

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
17from docutils.core import publish_parts
18from docutils.writers.html4css1 import Writer
19
20SETTINGS = {
21    'cloak_email_addresses': True,
22    'file_insertion_enabled': False,
23    'raw_enabled': False,
24    'strip_comments': True,
25    'doctitle_xform': False,
26    'report_level': 5,
27}
28
29def main():
30    """
31    Parses the given ReST file or the redirected string input and returns the
32    HTML body.
33
34    Usage: rest2html < README.rst
35           rest2html README.rst
36    """
37    try:
38        text = open(sys.argv[1], 'r').read()
39    except IOError: # given filename could not be found
40        return ''
41    except IndexError: # no filename given
42        text = sys.stdin.read()
43
44    parts = publish_parts(text, writer=Writer(), settings_overrides=SETTINGS)
45    if 'html_body' in parts:
46        html = parts['html_body']
47        return html.encode('utf-8')
48    return ''
49
50if __name__ == '__main__':
51    print main()