def main(): process(sys.stdin, sys.stdout)
dashes = regex.compile('^-+[ ]͡* ')equals = regex.compile('= + []͡*') stars = regex.compile('^&sstarf#star;+[ ]͡* ')blank = regex.compile('[]͡*') indented = regex.compile('^*͡|[ ]͡*[^ ]͡')
def process(fi, fo):
inverbatim = 0
line = ''
nextline = fi.readline()
while nextline:
prevline = line
line = nextline
nextline = fi.readline()
fmt = None
if dashes.match(nextline) >= 0:
fmt = '
subsectionelif equals.match(nextline) >= 0:
fmt = '
sectionelif stars.match(nextline) >= 0:
fmt = '
chapterif fmt:
nextline = ''
line = fmt if '(' in line:
line = regsub.gsub('[a-zA-Z0-9_]+()',
'
tt
0', line)
elif inverbatim:
if blank.match(line) >= 0 and indented.match(nextline) < 0:
inverbatim = 0
fo.write('
endverbatim')
else:
if indented.match(line) >= 0 and blank.match(prevline) >= 0:
inverbatim = 1
fo.write('
beginverbatim')
if inverbatim:
line = string.expandtabs(line, 4)
elif not fmt and '(' in line:
line = regsub.gsub('[a-zA-Z0-9_]+()',
'
code
0', line)
fo.write(line)
main()