Created
November 12, 2011 11:23
-
-
Save bebraw/1360404 to your computer and use it in GitHub Desktop.
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 characters
| import subprocess | |
| import sys | |
| def convert(source, from_format, to_format): | |
| # original version: http://osiux.com/html-to-restructured-text-in-python-using-pandoc | |
| # supported formats at http://johnmacfarlane.net/pandoc/ | |
| # raises OSError if pandoc is not found! | |
| p = subprocess.Popen(['pandoc', '--from=' + from_format, '--to=' + to_format], | |
| stdin=subprocess.PIPE, stdout=subprocess.PIPE | |
| ) | |
| if sys.version_info[0] == 3: | |
| return p.communicate(bytes(source, 'UTF-8'))[0] | |
| return p.communicate(source)[0] | |
| # example | |
| readme = open('README.md').read() # might want to use "with" to make sure it gets closed | |
| output = convert(readme, 'markdown', 'rst') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think we need to reopen this. It doesn't seem to install properly, see https://travis-ci.org/pycontribs/tendo/jobs/47505164