mirror of https://github.com/python/cpython
Added code to recognize http/ftp URLs and email addresses, and add <A>
tags for them.
This commit is contained in:
parent
821a558f39
commit
5527db5b76
|
@ -9,8 +9,6 @@ XXX TO DO
|
||||||
- next/prev/index links in do_show?
|
- next/prev/index links in do_show?
|
||||||
- should have files containing section headers
|
- should have files containing section headers
|
||||||
- customize rcs command pathnames
|
- customize rcs command pathnames
|
||||||
- recognize urls and email addresses and turn them into <A> tags
|
|
||||||
- use cookies to keep Name/email the same
|
|
||||||
- explanation of editing somewhere
|
- explanation of editing somewhere
|
||||||
- various embellishments, GIFs, crosslinks, hints, etc.
|
- various embellishments, GIFs, crosslinks, hints, etc.
|
||||||
- create new sections
|
- create new sections
|
||||||
|
@ -582,7 +580,7 @@ class FAQServer:
|
||||||
else:
|
else:
|
||||||
print '<P>'
|
print '<P>'
|
||||||
else:
|
else:
|
||||||
if line == string.lstrip(line): # I.e., no leading whitespace
|
if line[0] not in string.whitespace:
|
||||||
if pre:
|
if pre:
|
||||||
print '</PRE>'
|
print '</PRE>'
|
||||||
pre = 0
|
pre = 0
|
||||||
|
@ -590,7 +588,7 @@ class FAQServer:
|
||||||
if not pre:
|
if not pre:
|
||||||
print '<PRE>'
|
print '<PRE>'
|
||||||
pre = 1
|
pre = 1
|
||||||
print cgi.escape(line)
|
print self.translate(line)
|
||||||
if pre:
|
if pre:
|
||||||
print '</PRE>'
|
print '</PRE>'
|
||||||
pre = 0
|
pre = 0
|
||||||
|
@ -658,6 +656,38 @@ class FAQServer:
|
||||||
</HTML>
|
</HTML>
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
translate_prog = None
|
||||||
|
|
||||||
|
def translate(self, text):
|
||||||
|
if not self.translate_prog:
|
||||||
|
import regex
|
||||||
|
url = '\(http\|ftp\)://[^ \t\r\n]*'
|
||||||
|
email = '\<[-a-zA-Z0-9._]+@[-a-zA-Z0-9._]+'
|
||||||
|
self.translate_prog = prog = regex.compile(url + "\|" + email)
|
||||||
|
else:
|
||||||
|
prog = self.translate_prog
|
||||||
|
i = 0
|
||||||
|
list = []
|
||||||
|
while 1:
|
||||||
|
j = prog.search(text, i)
|
||||||
|
if j < 0:
|
||||||
|
break
|
||||||
|
list.append(cgi.escape(text[i:j]))
|
||||||
|
i = j
|
||||||
|
url = prog.group(0)
|
||||||
|
while url[-1] in ");:,.?":
|
||||||
|
url = url[:-1]
|
||||||
|
url = cgi.escape(url)
|
||||||
|
if ':' in url:
|
||||||
|
repl = '<A HREF="%s">%s</A>' % (url, url)
|
||||||
|
else:
|
||||||
|
repl = '<A HREF="mailto:%s"><%s></A>' % (url, url)
|
||||||
|
list.append(repl)
|
||||||
|
i = i + len(url)
|
||||||
|
j = len(text)
|
||||||
|
list.append(cgi.escape(text[i:j]))
|
||||||
|
return string.join(list, '')
|
||||||
|
|
||||||
print "Content-type: text/html"
|
print "Content-type: text/html"
|
||||||
dt = 0
|
dt = 0
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue