Skip to content

Instantly share code, notes, and snippets.

@wolfy1339
Forked from sivel/gfm2html
Last active June 12, 2017 17:47
Show Gist options
  • Save wolfy1339/b82928e8e6960b86f37f9cddd188d897 to your computer and use it in GitHub Desktop.
Save wolfy1339/b82928e8e6960b86f37f9cddd188d897 to your computer and use it in GitHub Desktop.
Code to convert github flavored markdown to RST
#!/usr/bin/env python
from __future__ import print_function
import pandoc
import requests
import sys
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',
json={'text': markdown, 'mode': 'markdown'})
html = re.sub(r'(<h\d>)\n<a[^>]+><span[^>]+></span></a>([^<]+)(</h\d>)',
r'\1\2\3', r.text).encode('utf-8', 'replace')
print(pypandoc.convert_text(html, 'rst', format='md'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment