forked from hyperai/tvm-cn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rst2md.sh
executable file
·42 lines (34 loc) · 980 Bytes
/
rst2md.sh
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
40
41
42
#!/bin/bash
# This script was created to convert a directory full of rst files into
# markdown equivalents. It uses pandoc to do the conversion.
#
# 1. Install pandoc from https://pandoc.org/
# 2. Run the script
#
# By default this will keep the original .rst file
#
# Original by https://gist.github.com/stupergenius/b43d38fbff0547c96322e3f44264a969
# Modified by Tunghsiao Liu <[email protected]>
set -o errexit
set -o nounset
set -o pipefail
_main() {
path=$1
for file in $(find $path -name '*.rst'); do
local pwd=$(pwd)
local filename_md=$(echo $file | sed "s/\.rst$/\.md/g")
local filename_orig=$(echo $file | sed "s|$pwd|.|g")
echo "Converting $filename_orig"
pandoc ${file} --from rst --to markdown --standalone --eol lf \
--shift-heading-level-by=1 --output "${filename_md}"
# Uncomment this line to delete the source file.
# rm "${file}"
done
}
main() {
oldifs=$IFS
IFS=$'\n'
_main ${1:-$(pwd)}
IFS=$oldifs
}
main $@