-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathPandoc_convert_md_to_rst.py
39 lines (29 loc) · 1.06 KB
/
Pandoc_convert_md_to_rst.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
# -*- coding: utf-8 -*-
"""
Simple script to convert markdown files into RsT files using Pandoc.
Usage: Put all md-files into a same directory ('indir') and specify output directory with 'outdir' variable. You may need to run this with
administrator rights (from cmd-prompt). The names of the rst files are using the same filename as their markdown counterparts.
Created on Mon Feb 20 23:50:55 2017
@author: hentenka
"""
import subprocess
import glob
import os
# Input directory for md-files
indir = r"C:\HY-DATA\HENTENKA\KOODIT\Opetus\Geo-Python\md\L7"
# Output directory for rst-files
outdir = r"C:\HY-DATA\HENTENKA\KOODIT\Opetus\Geo-Python\rst\L7"
# Read all md files
files = glob.glob(os.path.join(indir, "*.md"))
# Iterate over MD-files and convert them to RST
for f in files:
print(f)
# Basename
basename = os.path.basename(f)
# Output path
opath = os.path.join(outdir, basename.replace('.md', '.rst'))
# Command
cmd = "pandoc --from=markdown --to=rst --output=%s %s" % (opath, f)
print(cmd)
# Execute
subprocess.call(cmd)