#!/usr/bin/python
import sys
def entity_quote(txt):
return txt.replace("&", "&").replace("<", "<").replace(">", ">")
def wrap(elem, txt):
return "<%s>%s%s>" % (elem, entity_quote(txt), elem)
def do_a_slide(f):
print ""
for line in f:
if line == "\n":
print ""
break
elif line.startswith("= "):
print wrap("header", line[2:].rstrip())
elif line.startswith("* "):
print wrap("bullet", line[2:].rstrip())
elif line.startswith("+ "):
print wrap("subbullet", line[2:].rstrip())
elif line.startswith("@ "):
# handle .find("@") to construct mailto: urls
print wrap("url", line[2:].rstrip())
elif line.startswith("| "):
print wrap("raw", line[2:].rstrip())
else:
sys.exit("Slide Huh?" + line)
else:
raise EOFError()
def do_a_header(f):
print "\n".join([""
''
''])
for line in f:
if line == "\n":
break
elif line.startswith("TITLE: "):
print wrap("title", line.lstrip("TITLE:").strip())
elif line.startswith("AUTHOR: "):
print wrap("author", line.lstrip("AUTHOR:").strip())
elif line.startswith("DATE: "):
print wrap("date", line.lstrip("DATE:").strip())
else:
sys.exit("Header Huh?" + line)
def do_a_footer(f):
print "\n".join(["", ""])
if __name__ == "__main__":
f = sys.stdin
do_a_header(f)
try:
while 1:
do_a_slide(f)
except EOFError:
do_a_footer(f)