@@ -1343,7 +1343,42 @@ class StringHTMLProperty(HTMLProperty):
13431343 )''' , re .X | re .I )
13441344 protocol_re = re .compile ('^(ht|f)tp(s?)://' , re .I )
13451345
1346- def _hyper_repl_item (self ,match ,replacement ):
1346+
1347+
1348+ def _hyper_repl (self , match ):
1349+ if match .group ('url' ):
1350+ return self ._hyper_repl_url (match , '<a href="%s">%s</a>%s' )
1351+ elif match .group ('email' ):
1352+ return self ._hyper_repl_email (match , '<a href="mailto:%s">%s</a>' )
1353+ elif len (match .group ('id' )) < 10 :
1354+ return self ._hyper_repl_item (match ,
1355+ '<a href="%(cls)s%(id)s">%(item)s</a>' )
1356+ else :
1357+ # just return the matched text
1358+ return match .group (0 )
1359+
1360+ def _hyper_repl_url (self , match , replacement ):
1361+ u = s = match .group ('url' )
1362+ if not self .protocol_re .search (s ):
1363+ u = 'http://' + s
1364+ if s .endswith ('>' ):
1365+ # catch an escaped ">" at the end of the URL
1366+ u = s = s [:- 4 ]
1367+ e = '>'
1368+ elif s .count ('(' ) != s .count (')' ):
1369+ # don't include extraneous ')' in the link
1370+ pos = s .rfind (')' )
1371+ e = s [pos :]
1372+ u = s = s [:pos ]
1373+ else :
1374+ e = ''
1375+ return replacement % (u , s , e )
1376+
1377+ def _hyper_repl_email (self , match , replacement ):
1378+ s = match .group ('email' )
1379+ return replacement % (s , s )
1380+
1381+ def _hyper_repl_item (self , match , replacement ):
13471382 item = match .group ('item' )
13481383 cls = match .group ('class' ).lower ()
13491384 id = match .group ('id' )
@@ -1356,32 +1391,6 @@ def _hyper_repl_item(self,match,replacement):
13561391 except KeyError :
13571392 return item
13581393
1359- def _hyper_repl (self , match ):
1360- if match .group ('url' ):
1361- u = s = match .group ('url' )
1362- if not self .protocol_re .search (s ):
1363- u = 'http://' + s
1364- if s .endswith ('>' ):
1365- # catch an escaped ">" at the end of the URL
1366- u = s = s [:- 4 ]
1367- e = '>'
1368- elif s .count ('(' ) != s .count (')' ):
1369- # don't include extraneous ')' in the link
1370- pos = s .rfind (')' )
1371- e = s [pos :]
1372- u = s = s [:pos ]
1373- else :
1374- e = ''
1375- return '<a href="%s">%s</a>%s' % (u , s , e )
1376- elif match .group ('email' ):
1377- s = match .group ('email' )
1378- return '<a href="mailto:%s">%s</a>' % (s , s )
1379- elif len (match .group ('id' )) < 10 :
1380- return self ._hyper_repl_item (match ,
1381- '<a href="%(cls)s%(id)s">%(item)s</a>' )
1382- else :
1383- # just return the matched text
1384- return match .group (0 )
13851394
13861395 def _hyper_repl_rst (self , match ):
13871396 if match .group ('url' ):
@@ -2281,8 +2290,9 @@ def menu(self, size=None, height=None, showid=0, additional=[],
22812290 l .append ('</select>' )
22822291 return '\n ' .join (l )
22832292
2293+
22842294# set the propclasses for HTMLItem
2285- propclasses = (
2295+ propclasses = [
22862296 (hyperdb .String , StringHTMLProperty ),
22872297 (hyperdb .Number , NumberHTMLProperty ),
22882298 (hyperdb .Boolean , BooleanHTMLProperty ),
@@ -2291,7 +2301,17 @@ def menu(self, size=None, height=None, showid=0, additional=[],
22912301 (hyperdb .Password , PasswordHTMLProperty ),
22922302 (hyperdb .Link , LinkHTMLProperty ),
22932303 (hyperdb .Multilink , MultilinkHTMLProperty ),
2294- )
2304+ ]
2305+
2306+ def register_propclass (prop , cls ):
2307+ for index ,propclass in enumerate (propclasses ):
2308+ p , c = propclass
2309+ if prop == p :
2310+ propclasses [index ] = (prop , cls )
2311+ break
2312+ else :
2313+ propclasses .append ((prop , cls ))
2314+
22952315
22962316def make_sort_function (db , classname , sort_on = None ):
22972317 """Make a sort function for a given class
0 commit comments