Guido van Rossum | 7a2dba2 | 1993-11-05 14:45:11 +0000 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | import regex |
Guido van Rossum | db65a6c | 1993-11-05 17:11:16 +0000 | [diff] [blame] | 4 | import regsub |
Guido van Rossum | 7a2dba2 | 1993-11-05 14:45:11 +0000 | [diff] [blame] | 5 | import string |
| 6 | import getopt |
| 7 | |
| 8 | def main(): |
| 9 | process(sys.stdin, sys.stdout) |
| 10 | |
| 11 | dashes = regex.compile('^-+[ \t]*$') |
| 12 | equals = regex.compile('^=+[ \t]*$') |
| 13 | stars = regex.compile('^\*+[ \t]*$') |
| 14 | blank = regex.compile('^[ \t]*$') |
| 15 | indented = regex.compile('^\( *\t\| \)[ \t]*[^ \t]') |
| 16 | |
| 17 | def 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 Rossum | db65a6c | 1993-11-05 17:11:16 +0000 | [diff] [blame] | 35 | if '(' in line: |
| 36 | line = regsub.gsub('[a-zA-Z0-9_]+()', |
| 37 | '{\\\\tt \\0}', line) |
Guido van Rossum | 7a2dba2 | 1993-11-05 14:45:11 +0000 | [diff] [blame] | 38 | 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 Rossum | db65a6c | 1993-11-05 17:11:16 +0000 | [diff] [blame] | 50 | elif not fmt and '(' in line: |
| 51 | line = regsub.gsub('[a-zA-Z0-9_]+()', |
| 52 | '\\\\code{\\0}', line) |
Guido van Rossum | 7a2dba2 | 1993-11-05 14:45:11 +0000 | [diff] [blame] | 53 | fo.write(line) |
| 54 | |
Guido van Rossum | 6f0132f | 1993-11-19 13:13:22 +0000 | [diff] [blame] | 55 | main() |