Is there a Text to HTML conversion module?

Gillou nospam at bigfoot.com
Tue Jun 18 07:23:14 EDT 2002


Did not test but...

Zope has got a StructuredText package that can be used "standalone" (outside
of a Zope site).

www.zope.org

Otherwise, here's a simple snip that will help if you want to do it by
yourself : It changes the markup from the original plain text and replaces
against entities and changes http, ftp and mail markups against hyperlinks.
Can be improved of course.

import string, re
# Subtitute HTML markup chars by entities
text = string.replace(text, '&', '&')
text = string.replace(text, '<', '<')
text = string.replace(text, '>', '>')
text = string.replace(text, '\n', '</p>\n<p>')
# Make hyperlinks from HTTP or FTP URLs
pat = re.compile(r'((ftp|http)://[\w-]+(?:\.[\w-]+)*(?:/[\w\-\.?=]*)*)')
text = pat.sub('<a href="\\1">\\1</a>', text)
# Make hyperlinks from email addresses
pat = re.compile(r'([\w-]+(?:\.[\w-]+)*@[\w-]+(?:\.[\w-]+)*)')
text = pat.sub('<a href="mailto:\\1">\\1</a>', text)

HTH

--Gilles

"James T. Dennis" <jadestar at idiom.com> a écrit dans le message news:
aempf6$1nq2$1 at news.idiom.com...
> Erik Max Francis <max at alcyone.com> wrote:
> > Andrew Dalke wrote:
>
> >> <wink/>
>
> >>>(sorry... couldn't resist)
> >> Neither could I.  :)
> > Ah, but that's XML, not HTML.  :-)
>
>  Of course it might be some future extension to XHTML
>




More information about the Python-list mailing list