[Florob] Improved URL matching.

We don't match all valid URIs like blub:blaa but include common used (non)-urls like www.google.de
This commit is contained in:
Stephan Erb 2008-07-08 18:49:51 +00:00
parent 8da186bffb
commit fca6bdbbc4
3 changed files with 18 additions and 20 deletions

View File

@ -251,6 +251,7 @@ class Config:
'attach_notifications_to_systray': [opt_bool, False, _('If True, notification windows from notification-daemon will be attached to systray icon.')],
'check_idle_every_foo_seconds': [opt_int, 2, _('Choose interval between 2 checks of idleness.')],
'latex_png_dpi': [opt_str, '108',_('Change the value to change the size of latex formulas displayed. The higher is larger.') ],
'uri_schemes': [opt_str, 'http https ftp ftps gopher news ed2k irc magnet sip', _('Valid uri schemes. Only schemes in this list will be made accepted as "real" uri.')],
}
__options_per_key = {

View File

@ -907,19 +907,8 @@ class ConversationTextview:
self.images.append(img)
# add with possible animation
self.tv.add_child_at_anchor(img, anchor)
#FIXME: one day, somehow sync with regexp in gajim.py
elif special_text.startswith('http://') or \
special_text.startswith('www.') or \
special_text.startswith('ftp://') or \
special_text.startswith('ftp.') or \
special_text.startswith('https://') or \
special_text.startswith('gopher://') or \
special_text.startswith('news://') or \
special_text.startswith('ed2k://') or \
special_text.startswith('irc://') or \
special_text.startswith('sip:') or \
special_text.startswith('magnet:'):
# it's a url
elif special_text.startswith('www.') or \
special_text.startswith('ftp.'):
tags.append('url')
use_other_tags = False
elif special_text.startswith('mailto:') or \
@ -991,9 +980,16 @@ class ConversationTextview:
buffer.insert(end_iter, special_text)
use_other_tags = False
else:
#it's a url
tags.append('url')
use_other_tags = False
# Check if we accept this as an uri
schemes = gajim.config.get('uri_schemes').split()
for scheme in schemes:
if special_text.startswith(scheme + ':'):
tags.append('url')
use_other_tags = False
# It's not a accepted uri
if use_other_tags:
end_iter = buffer.get_end_iter()
buffer.insert_with_tags_by_name(end_iter, special_text, *other_tags)
if len(tags) > 0:
end_iter = buffer.get_end_iter()
@ -1171,6 +1167,7 @@ class ConversationTextview:
# /me is replaced by name if name is given
if name and (text.startswith('/me ') or text.startswith('/me\n')):
text = '* ' + name + text[3:]
text_tags.append('italic')
# detect urls formatting and if the user has it on emoticons
index = self.detect_and_print_special_text(text, text_tags)

View File

@ -2274,9 +2274,9 @@ class Interface:
# \S*[^\s\W] --> in the matching string don't match ? or ) etc.. if at the end
# so http://be) will match http://be and http://be)be) will match http://be)be
prefixes = '|'.join((r'http://', r'https://', r'gopher://', r'news://',
r'ftp://', r'ed2k://', r'irc://', r'magnet:', r'sip:', r'www\.',
r'ftp\.'))
legacy_prefixes = r"((?<=\()(www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))"\
r"|((www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+"\
r"\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+)"
# NOTE: it's ok to catch www.gr such stuff exist!
#FIXME: recognize xmpp: and treat it specially
@ -2295,7 +2295,7 @@ class Interface:
latex = r'|\$\$[^$\\]*?([\]\[0-9A-Za-z()|+*/-]|[\\][\]\[0-9A-Za-z()|{}$])(.*?[^\\])?\$\$'
basic_pattern = links + '|' + mail
basic_pattern = links + '|' + mail + '|' + legacy_prefixes
if gajim.config.get('use_latex'):
basic_pattern += latex