all repos — markup @ v0.3.0

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}
27
28def main():
29    """
30    Parses the given ReST file or the redirected string input and returns the
31    HTML body.
32
33    Usage: rest2html < README.rst
34           rest2html README.rst
35    """
36    try:
37        text = open(sys.argv[1], 'r').read()
38    except IOError: # given filename could not be found
39        return ''
40    except IndexError: # no filename given
41        text = sys.stdin.read()
42
43    parts = publish_parts(text, writer=Writer(), settings_overrides=SETTINGS)
44    if 'html_body' in parts:
45        return parts['html_body']
46    return ''
47
48if __name__ == '__main__':
49    print main()