当前位置 : 主页 > 编程语言 > python >

python即时标记

来源:互联网 收集:自由互联 发布时间:2023-03-22
功能 :读入文本内容转化为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>'

上一篇:hdu 4465 Candy(概率公式+极大乘极小,4级)
下一篇:没有了
网友评论