formatting plain text to html
Cliff, or a close facsimile
cjc26 at nospam.cornell.edu
Mon Sep 13 20:48:39 EDT 1999
Pada 13 Sep 1999 21:06:04 +0100, david.maslen at iname.com bilang:
| I have a bunch of plain text notes. I want to format them so that any
| URL references ie. 'http://www.python.org/' are replaced by
| '<a href="http://www.python.org/">http://www.python.org/</a>'
|
| There are probably a few other niceties such as replacing linefeeds
| with <p>, but that isn't so important.
|
| Should I just get started with the strings and re modules? Or is there
| some code in existance that will make this task easier?
I don't know, but the following seems to work:
>>> teststr='look at my webpage http://www.python.org/ I am so l33t'
>>> re.sub('(http://[\w\-\?%~./]+)', r'<A HREF="\1">\1</A>', teststr)
'look at my webpage <A HREF="http://www.python.org/">http://www.python.org/"</A
> I am so l33t'
Are there any other characters permitted in URL's?
--
cliff crawford http://www.people.cornell.edu/pages/cjc26/
There are more stars in the sky than there are
-><- grains of sand on all the beaches of the world.
More information about the Python-list
mailing list