Created
November 12, 2011 11:23
-
-
Save bebraw/1360404 to your computer and use it in GitHub Desktop.
This file contains 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') |
@fred6: I updated the Gist. Thanks! :)
I think we need to reopen this. It doesn't seem to install properly, see https://travis-ci.org/pycontribs/tendo/jobs/47505164
thanks for this!! this is perfect
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This doesn't quite work in python 3.2 for me. I had to cast 'source' to bytes:
return p.communicate(bytes(source, 'UTF-8'))[0]