-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathrsthacks.py
More file actions
executable file
·29 lines (22 loc) · 857 Bytes
/
rsthacks.py
File metadata and controls
executable file
·29 lines (22 loc) · 857 Bytes
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
#!/usr/bin/env python
# Pre-process rst source
from optparse import OptionParser
import re
_SCALE_RE = b'(:scale:\s+)(\d+):(\d+):(\d+)'
def process(file, format):
contents = open(file, 'rb').read()
if format == "html":
contents = re.sub(_SCALE_RE, r'\1\2', contents)
elif format == "latex":
contents = re.sub(_SCALE_RE, r'\1\3', contents)
elif format == "xml":
contents = re.sub(_SCALE_RE, r'\1\4', contents)
open(file + "2", 'wb').write(contents)
parser = OptionParser()
parser.add_option("-f", "--format", dest="format",
help="output format (html, latex, xml)", metavar="FMT")
o, a = parser.parse_args()
if o.format and o.format in ["html", "latex", "xml"] and a and len(a) == 1:
process(a[0], o.format)
else:
exit("Must specify a format (html, latex, xml) and a filename")