Converting text to html

Erik Max Francis max at alcyone.com
Fri Apr 4 17:51:23 EST 2003


achrist at easystreet.com wrote:

> Is there any recommended code available to convert plain text into
> text that can go into an html document without breaking it?  I
> think that I just have to do these three translations:
> 
>         < =>  <      > =>  >   &  =>  &
> 
> But I'm not sure if there are any others.  I've got to do this
> quite a bit while the user is waiting, so it would be nice to
> have something that did it in a way that was not a lot slower
> than any of the alternatives.

Use the cgi.escape function.  It ha san optional "quote" parameter that
will also convert double quotes to " for you as well.  Normally you
don't need that, but if you plan on putting something in a quoted
section you would.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ If the sky should fall, hold up your hands.
\__/ (a Spanish proverb)
    The laws list / http://www.alcyone.com/max/physics/laws/
 Laws, rules, principles, effects, paradoxes, etc. in physics.




More information about the Python-list mailing list