Author: steve-e Date: 2008-07-08 20:49:51 +0200 (Tue, 08 Jul 2008) New Revision: 9898
Modified: trunk/src/common/config.py trunk/src/conversation_textview.py trunk/src/gajim.py Log: [Florob] Improved URL matching.
We don't match all valid URIs like blub:blaa but include common used (non)-urls like www.google.de
Modified: trunk/src/common/config.py =================================================================== --- trunk/src/common/config.py 2008-07-07 23:04:10 UTC (rev 9897) +++ trunk/src/common/config.py 2008-07-08 18:49:51 UTC (rev 9898) @@ -251,6 +251,7 @@ '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 = {
Modified: trunk/src/conversation_textview.py =================================================================== --- trunk/src/conversation_textview.py 2008-07-07 23:04:10 UTC (rev 9897) +++ trunk/src/conversation_textview.py 2008-07-08 18:49:51 UTC (rev 9898) @@ -907,19 +907,8 @@ 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 @@ 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 @@ # /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)
Modified: trunk/src/gajim.py =================================================================== --- trunk/src/gajim.py 2008-07-07 23:04:10 UTC (rev 9897) +++ trunk/src/gajim.py 2008-07-08 18:49:51 UTC (rev 9898) @@ -2274,9 +2274,9 @@ # \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 @@
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