Created
September 14, 2013 15:35
-
-
Save sivel/6562987 to your computer and use it in GitHub Desktop.
Code to convert github flavored markdown to RST
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
#!/usr/bin/env python | |
import requests | |
import sys | |
import json | |
import re | |
if len(sys.argv) == 2: | |
markdown_file = sys.argv[1] | |
else: | |
markdown_file = 'README.md' | |
with open(markdown_file) as f: | |
markdown = f.read() | |
r = requests.post('https://api.github.com/markdown', | |
data=json.dumps({'text': markdown, 'mode': 'markdown'})) | |
html = re.sub(r'(<h\d>)\n<a[^>]+><span[^>]+></span></a>([^<]+)(</h\d>)', | |
r'\1\2\3', r.text) | |
print html.encode('utf-8', 'replace') |
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
#!/bin/bash | |
MD='README.md' | |
if [ ! -z $1 ]; then | |
MD=$1 | |
fi | |
pandoc --from=html --to=rst --output=README.rst <(gfm2html $MD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment