Last active
August 29, 2015 14:11
-
-
Save brandjon/6c00cd75dae7bac62caa to your computer and use it in GitHub Desktop.
Convert markdown to rst and remove links along the way
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
from pypandoc import convert | |
from pandocfilters import walk | |
import json | |
def delink(key, value, format, meta): | |
if key == 'Link': | |
text, _ = value | |
return text | |
with open('in.md', 'rt') as infile: | |
indata = infile.read() | |
jsondata = convert(indata, 'json', format='markdown') | |
jsontree = json.loads(jsondata) | |
jsontree = walk(jsontree, delink, None, None) | |
jsondata = json.dumps(jsontree) | |
outdata = convert(jsondata, 'rst', format='json') | |
with open('out.rst', 'wt') as outfile: | |
outfile.write(outdata) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment