Created
September 4, 2013 13:18
-
-
Save dokterbob/6436801 to your computer and use it in GitHub Desktop.
Revisions
-
dokterbob created this gist
Sep 4, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #!/usr/bin/env python import sys import argparse import tempfile import webbrowser import time from docutils.core import publish_string import locale try: locale.setlocale(locale.LC_ALL, '') except: pass def main(argv=None): parser = argparse.ArgumentParser(description= 'Render reStructuredText straight to the browser.' ) parser.add_argument('filename', type=str) args = parser.parse_args() source_file = open(args.filename) print 'Rendering and viewing', source_file.name with tempfile.NamedTemporaryFile(suffix='.html') as f: # Render the file html = publish_string(source=source_file.read(), writer_name='html') # Write output to file f.write(html) f.flush() fileurl = 'file://' + f.name # Open in the browser webbrowser.open(fileurl, new=2) # Wait 1 second for the browser to open it time.sleep(1) if __name__ == "__main__": sys.exit(main())