[PYTHON MATRIX-SIG] FAQ

Robin Friedrich friedric@rose.rsoc.rockwell.com
Fri, 26 Apr 1996 10:53:53 -0500


Hi Jim,
Whipped up this little script to htmlize your FAQ. Thought you might like it.

#!/bin/env python
# Script to htmlize Jim's FAQ. Might be generally useful though.
import regsub, regex, sys
try:
    file = sys.argv[1]
except IndexError:
    print 'Usage: '+sys.argv[0]+' filename'
    print 'The processed file will have the same name with a .html suffix added.'

outname = file+'.html'
out = open(outname, 'w')

httppat  = regex.compile('\(http:[^ \n]+\)')
ftppat   = regex.compile('\(ftp:[^ \n]+\)')
mailpat  = regex.compile('\(\w+@[^ ()\n]+\)')
headpat  = regex.compile('\(^[0-9]+).*$\)')
trailpat = regex.compile('\([^ ]$\)')

text = open(file).read()

out.write('<TITLE>Numerical Python FAQ</TITLE>\n') #change this to taste
out.write('<BODY>\n')

text = regsub.gsub(httppat, '<A Href="\\1">\\1</A>', text)
text = regsub.gsub(ftppat, '<A Href="\\1">\\1</A>', text)
text = regsub.gsub(mailpat, '<A Href="mailto:\\1">\\1</A>', text)
text = regsub.gsub(headpat, '<H4>\\1</H4>', text)
text = regsub.gsub('\n\n', '\n<P>', text)
text = regsub.gsub(trailpat, '\\1 ', text)

out.write(text)
out.write('\n</BODY>\n')

print 'Done.  Output may be found in '+outname

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================