txt是遵循markdown的规则写的
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import re
import markdown
#读取txt
a=open('test.txt')
b=a.read()
print(type(b))
abc=markdown.markdown(b)
a.close()
#正则表达式分成一个列表
input =re.findall(u'.*</[^>]+>',abc)
#改颜色
for i in range(len(input)):
if re.search(u'h1',input[i]):
input[i]='<div position: absolute style="color:#00FF00">'+input[i]+'</div>'
print(input[i])
elif re.search(u'h2',input[i]):
input[i] = '<div style="color:#0000FF">' + input[i] + '</div>'
elif re.search(u'<p>',input[i]):
input[i] = '<div style="color:#FF0000">' + input[i] + '</div>'
#写入HTML文件
GEN_HTML = "test.html"
h = open(GEN_HTML, 'w')
for i in range(len(input)):
h.write(input[i])
h.close()