功能 :读入文本内容转化为HTML import sysdef lines(file): for line in file: yield line yield '\n'def blocks(file): block = [] for line in lines(file): if line.strip(): block.append(line) elif block: yield ''.join(block).strip() b
功能 :读入文本内容转化为HTML
import sysdef lines(file): for line in file: yield line yield '\n'def blocks(file): block = [] for line in lines(file): if line.strip(): block.append(line) elif block: yield ''.join(block).strip() block = []import sys,refrom util import *print '<html><head><title>...</title><body>'title = Truefor block in blocks(sys.stdin): block = re.sub(r'\*(.+?)\*',r'<em>\1</em>',block) if title: print '<h1>' print block print '</h1>' title = False else: print '<p>' print block print '</p>'print '</body></html>'