forked from thehackerwithin/UofCSCBC2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrst2ghmd.py
executable file
·39 lines (27 loc) · 938 Bytes
/
rst2ghmd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# Viva!
# ~el Scopz
"""This utility converts rst to GitHub appropriate markdown. Note that
pandoc is not sufficient to have syntax highlighting work properly here.
"""
import os
import subprocess
def pandoc2gh(filename):
with open(filename, 'r') as f:
s = f.read()
s = s.replace("~~~~ {.sourceCode .python}\n", "```python\n")
s = s.replace("~~~~\n", "```\n")
with open(filename, 'w') as f:
f.write(s)
def main():
# get file lists
rstfiles = [os.path.join(p, f) for p, d, files in os.walk('.') for f in files]
rstfiles = [f for f in rstfiles if f.endswith('.rst')]
mdfiles = [f.rpartition('.')[0] + '.md' for f in rstfiles]
# convert to md
cmds = [['pandoc', rst, '-o', md] for rst, md in zip(rstfiles, mdfiles)]
map(subprocess.check_call, cmds)
# Munge pandoc md to gh md
map(pandoc2gh, mdfiles)
if __name__ == '__main__':
main()