Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Is there a Text to HTML conversion module?

0 views
Skip to first unread message

SA

unread,
Jun 3, 2002, 3:10:11 AM6/3/02
to
Does anyone know of a module that converts a text file to html?

I started writing my own, but decided I better make sure I'm not
re-inventing the wheel here.

Thanks.
SA

Peter Hansen

unread,
Jun 3, 2002, 7:57:56 AM6/3/02
to

You are probably looking for what has been labelled "Structured Text".
Try a search on google with that and "python"...

-Peter

Michael Chermside

unread,
Jun 3, 2002, 3:29:39 PM6/3/02
to
> Does anyone know of a module that converts a text file to html?

Sure!

def textToHtml(text):
return '<html><body><pre>%s</pre></body></head>' % text


<wink>

(sorry... couldn't resist)

-- Michael Chermside


Andrew Dalke

unread,
Jun 3, 2002, 5:19:24 PM6/3/02
to
Michael Chermside:

>def textToHtml(text):
> return '<html><body><pre>%s</pre></body></head>' % text

import cgi
def textToHtml(text):
return '<html><body><pre>%s</pre></body></html>' % cgi.escape(text)

><wink>

<wink/>

>(sorry... couldn't resist)

Neither could I. :)

Andrew
da...@dalkescientific.com

Erik Max Francis

unread,
Jun 3, 2002, 5:28:53 PM6/3/02
to
Andrew Dalke wrote:

> <wink/>
>
> >(sorry... couldn't resist)
>
> Neither could I. :)

Ah, but that's XML, not HTML. :-)

--
Erik Max Francis / m...@alcyone.com / http://www.alcyone.com/max/
__ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/ \ Who'd ever think it / Such a squalid little ending
\__/ The American and Florence, _Chess_
Church / http://www.alcyone.com/pyos/church/
A lambda calculus explorer in Python.

David Goodger

unread,
Jun 3, 2002, 11:51:14 PM6/3/02
to
SA wrote:
> Does anyone know of a module that converts a text file to html?

Try reStructuredText, part of Docutils (URLs below).

--
David Goodger <goo...@users.sourceforge.net> Open-source projects:
- Python Docutils: http://docutils.sourceforge.net/
(includes reStructuredText: http://docutils.sf.net/rst.html)
- The Go Tools Project: http://gotools.sourceforge.net/

James T. Dennis

unread,
Jun 18, 2002, 4:02:46 AM6/18/02
to
Erik Max Francis <m...@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

Gillou

unread,
Jun 18, 2002, 7:23:14 AM6/18/02
to
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, '&', '&amp;')
text = string.replace(text, '<', '&lt;')
text = string.replace(text, '>', '&gt;')
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" <jade...@idiom.com> a écrit dans le message news:
aempf6$1nq2$1...@news.idiom.com...

0 new messages