-
-
Save wolfy1339/b82928e8e6960b86f37f9cddd188d897 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 | |
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