add rest
Chris Wanstrath chris@ozmm.org
Fri, 30 Oct 2009 22:59:26 -0700
3 files changed,
55 insertions(+),
8 deletions(-)
A
lib/github/commands/rest2html
@@ -0,0 +1,48 @@
+#!/usr/bin/env python + +"""A small wrapper file for parsing ReST files at GitHub.""" + +__author__ = "Jannis Leidel" +__copyright__ = "Copyright (C) 2008 Jannis Leidel" +__license__ = "Public Domain" +__version__ = "0.1" + +try: + import locale + locale.setlocale(locale.LC_ALL, '') +except: + pass + +import sys +from docutils.core import publish_parts +from docutils.writers.html4css1 import Writer + +SETTINGS = { + 'cloak_email_addresses': True, + 'file_insertion_enabled': False, + 'raw_enabled': False, + 'strip_comments': True, +} + +def main(): + """ + Parses the given ReST file or the redirected string input and returns the + HTML body. + + Usage: rest2html < README.rst + rest2html README.rst + """ + try: + text = open(sys.argv[1], 'r').read() + except IOError: # given filename could not be found + return '' + except IndexError: # no filename given + text = sys.stdin.read() + + parts = publish_parts(text, writer=Writer(), settings_overrides=SETTINGS) + if 'html_body' in parts: + return parts['html_body'] + return '' + +if __name__ == '__main__': + print main()
M
lib/github/markups.rb
→
lib/github/markups.rb
@@ -6,7 +6,4 @@ markup(:redcloth, /textile/) do |content|
RedCloth.new(content).to_html end -markup('github/markup/rest', /rest|rst/) do |content| - GitHub::Markup::ReST.translate(content) -end - +command(:rest2html, /rest|rst/)
M
test/markup_test.rb
→
test/markup_test.rb
@@ -47,9 +47,11 @@ 1. Blah blah ``code`` blah
2. More ``code``, hooray input -<ul> -\t<li>One</li> -\t<li>Two</li> -</ul> +<div class="document"> +<ol class="arabic simple"> +<li>Blah blah <tt class="docutils literal">code</tt> blah</li> +<li>More <tt class="docutils literal">code</tt>, hooray</li> +</ol> +</div>\n output end