Created
April 16, 2013 07:17
-
-
Save mickhan/5394008 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def txt2html(txt): | |
'''将txt以行为单位加上<li></li>标签''' | |
def escape(txt): | |
'''将txt文本中的空格、&、<、>、(")、(')转化成对应的的字符实体,以方便在html上显示''' | |
txt = txt.replace('&','&') | |
txt = txt.replace(' ',' ') | |
txt = txt.replace('<','<') | |
txt = txt.replace('>','>') | |
txt = txt.replace('"','"') | |
txt = txt.replace('\'',''') | |
return txt | |
txt = escape(txt) | |
lines = txt.split('\n') | |
for i, line in enumerate(lines): | |
lines[i] = '<li>' + line + '</li>' | |
#lines[i] = '<p>' + line + '</p>' | |
txt = ''.join(lines) | |
return txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment