Skip to content

Instantly share code, notes, and snippets.

@sivel
Created September 14, 2013 15:35
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sivel/6562987 to your computer and use it in GitHub Desktop.
Save sivel/6562987 to your computer and use it in GitHub Desktop.
Code to convert github flavored markdown to RST
#!/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')
#!/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