blob: 93d0587d30487a936904c6d8924e21a1621b10f4 [file] [log] [blame]
Guido van Rossum7a2dba21993-11-05 14:45:11 +00001import os
2import sys
3import regex
Guido van Rossumdb65a6c1993-11-05 17:11:16 +00004import regsub
Guido van Rossum7a2dba21993-11-05 14:45:11 +00005import string
6import getopt
7
8def main():
9 process(sys.stdin, sys.stdout)
10
11dashes = regex.compile('^-+[ \t]*$')
12equals = regex.compile('^=+[ \t]*$')
13stars = regex.compile('^\*+[ \t]*$')
14blank = regex.compile('^[ \t]*$')
15indented = regex.compile('^\( *\t\| \)[ \t]*[^ \t]')
16
17def process(fi, fo):
18 inverbatim = 0
19 line = '\n'
20 nextline = fi.readline()
21 while nextline:
22 prevline = line
23 line = nextline
24 nextline = fi.readline()
25 fmt = None
26 if dashes.match(nextline) >= 0:
27 fmt = '\\subsection{%s}\n'
28 elif equals.match(nextline) >= 0:
29 fmt = '\\section{%s}\n'
30 elif stars.match(nextline) >= 0:
31 fmt = '\\chapter{%s}\n'
32 if fmt:
33 nextline = '\n'
34 line = fmt % string.strip(line)
Guido van Rossumdb65a6c1993-11-05 17:11:16 +000035 if '(' in line:
36 line = regsub.gsub('[a-zA-Z0-9_]+()',
37 '{\\\\tt \\0}', line)
Guido van Rossum7a2dba21993-11-05 14:45:11 +000038 elif inverbatim:
39 if blank.match(line) >= 0 and \
40 indented.match(nextline) < 0:
41 inverbatim = 0
42 fo.write('\\end{verbatim}\n')
43 else:
44 if indented.match(line) >= 0 and \
45 blank.match(prevline) >= 0:
46 inverbatim = 1
47 fo.write('\\begin{verbatim}\n')
48 if inverbatim:
49 line = string.expandtabs(line, 4)
Guido van Rossumdb65a6c1993-11-05 17:11:16 +000050 elif not fmt and '(' in line:
51 line = regsub.gsub('[a-zA-Z0-9_]+()',
52 '\\\\code{\\0}', line)
Guido van Rossum7a2dba21993-11-05 14:45:11 +000053 fo.write(line)
54
Guido van Rossum6f0132f1993-11-19 13:13:22 +000055main()