Welcome, guest | Sign In | My Account | Store | Cart

将文本排版转化为html中相同的排版。 为google blog服务

Python, 9 lines
1
2
3
4
5
6
7
8
9
#文本原样到html中
#对换行符的处理
#需求产生于:Google Blog
line_break="\n"

data=file("e://untitled.txt","r").read()
out=data.replace(line_break,"<br/>")

file("c://out.txt","w").write(out)

3 comments

Ash 15 years, 1 month ago  # | flag

Well this is not very helpful, you need to do a lot more for a real HTML conversion. And why would you write out to .txt instead of .html? E.g. converting some Wiki-Markup to HTML converts Lists to <ul> elements and the like would be also necessary for a more interesting use case

kibleur christophe 15 years, 1 month ago  # | flag

Sure, you're winning a place inside the PyPy team with such awesome scripts... Waiting for html2txt version (a one liner maybe ?).

Sandy Norton 15 years, 1 month ago  # | flag

Please do not clutter up the recipe space with such trivialities, otherwise you might as well make "print 'hello world'" a recipe...

Created by nillgump nillgump on Thu, 5 Mar 2009 (MIT)
Python recipes (4591)
nillgump nillgump's recipes (6)

Required Modules

  • (none specified)

Other Information and Tasks