-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathpanletter
executable file
·52 lines (42 loc) · 1.74 KB
/
panletter
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
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
import os, sys, argparse
# Read input and output arguments, keeping all others as they are
parser = argparse.ArgumentParser(prog='panletter',
formatter_class=argparse.RawDescriptionHelpFormatter,
description="""
Convert one or more markdown files to a letter in PDF or LaTeX format using
the scrlttr2 template. For more information on using this tool and the template,
visit
https://github.com/JensErat/pandoc-scrlttr2
(c) Jens Erat 2014, BSD-License
""",
epilog='''
All pandoc options can be used.
Example: panletter -fmarkdown+pipe_tables input-letter.md
This example will enable the pandoc extension pipe_tables and allow to
include tables in the letter.
Beware that there is no space allowed between the pandoc option switch
(here -f) and the parameter, as otherwise panletter will consider the
parameter as an input file.
'''
)
parser.add_argument('-o', '--output',
help="""
Output file name. If ommited, the first input's file name with .pdf extension
will be used. To generate a LaTeX file, pass a filename with .tex extension.
""",
metavar='file')
parser.add_argument('input',
nargs='+',
help='one or more input files',
metavar='file')
(files, options) = parser.parse_known_args()
# If output is not set, use first input file's name
if files.output is None:
files.output = os.path.splitext(files.input[0])[0] + '.pdf'
# Call pandoc
os.execvp('pandoc', [
'pandoc',
'--template=scrlttr2',
'-o', files.output
] + options + files.input)