-
Notifications
You must be signed in to change notification settings - Fork 0
/
markdown-to-pdf
executable file
·40 lines (36 loc) · 1.2 KB
/
markdown-to-pdf
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
#!/usr/bin/python
from subprocess import call
from re import sub
from string import replace
import sys
import argparse
pandoc_opts = [
'-t', 'latex',
'-V', 'fontsize=10pt',
'-V', 'colorlinks',
'--template', 'eisvogel.tex',
'--listings'
]
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=\
"Make a call to pandoc to create a nice pdf file from markdown")
parser.add_argument("input_file",
help="A markdown file to convert to pdf")
args = parser.parse_args()
# process input
output_file = replace(args.input_file, '.md', '.pdf')
call_string = ['pandoc'] \
+ pandoc_opts \
+ ['-s', args.input_file ] \
+ ['-o', output_file ]
print 'calling pandoc:\n\t', call_string
try:
retcode = call(call_string, stderr=sys.stderr, stdout=sys.stdout)
if retcode == 0:
print >>sys.stderr, "Pandoc is happy - output at ", output_file
elif retcode < 0:
print >>sys.stderr, "Pandoc was terminated by signal", -retcode
else:
print >>sys.stderr, "Pandoc returned", retcode
except OSError as e:
print >>sys.stderr, "Execution failed:", e