[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:
parent
8da186bffb
commit
fca6bdbbc4
|
@ -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.')],
|
'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.')],
|
'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.') ],
|
'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 = {
|
__options_per_key = {
|
||||||
|
|
|
@ -907,19 +907,8 @@ class ConversationTextview:
|
||||||
self.images.append(img)
|
self.images.append(img)
|
||||||
# add with possible animation
|
# add with possible animation
|
||||||
self.tv.add_child_at_anchor(img, anchor)
|
self.tv.add_child_at_anchor(img, anchor)
|
||||||
#FIXME: one day, somehow sync with regexp in gajim.py
|
elif special_text.startswith('www.') or \
|
||||||
elif special_text.startswith('http://') or \
|
special_text.startswith('ftp.'):
|
||||||
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
|
|
||||||
tags.append('url')
|
tags.append('url')
|
||||||
use_other_tags = False
|
use_other_tags = False
|
||||||
elif special_text.startswith('mailto:') or \
|
elif special_text.startswith('mailto:') or \
|
||||||
|
@ -991,9 +980,16 @@ class ConversationTextview:
|
||||||
buffer.insert(end_iter, special_text)
|
buffer.insert(end_iter, special_text)
|
||||||
use_other_tags = False
|
use_other_tags = False
|
||||||
else:
|
else:
|
||||||
#it's a url
|
# Check if we accept this as an uri
|
||||||
tags.append('url')
|
schemes = gajim.config.get('uri_schemes').split()
|
||||||
use_other_tags = False
|
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:
|
if len(tags) > 0:
|
||||||
end_iter = buffer.get_end_iter()
|
end_iter = buffer.get_end_iter()
|
||||||
|
@ -1171,6 +1167,7 @@ class ConversationTextview:
|
||||||
# /me is replaced by name if name is given
|
# /me is replaced by name if name is given
|
||||||
if name and (text.startswith('/me ') or text.startswith('/me\n')):
|
if name and (text.startswith('/me ') or text.startswith('/me\n')):
|
||||||
text = '* ' + name + text[3:]
|
text = '* ' + name + text[3:]
|
||||||
|
text_tags.append('italic')
|
||||||
# detect urls formatting and if the user has it on emoticons
|
# detect urls formatting and if the user has it on emoticons
|
||||||
index = self.detect_and_print_special_text(text, text_tags)
|
index = self.detect_and_print_special_text(text, text_tags)
|
||||||
|
|
||||||
|
|
|
@ -2274,9 +2274,9 @@ class Interface:
|
||||||
# \S*[^\s\W] --> in the matching string don't match ? or ) etc.. if at the end
|
# \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
|
# 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://',
|
legacy_prefixes = r"((?<=\()(www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+(?=\)))"\
|
||||||
r'ftp://', r'ed2k://', r'irc://', r'magnet:', r'sip:', r'www\.',
|
r"|((www|ftp)\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+"\
|
||||||
r'ftp\.'))
|
r"\.([A-Za-z0-9\.\-_~:/\?#\[\]@!\$&'\(\)\*\+,;=]|%[A-Fa-f0-9]{2})+)"
|
||||||
# NOTE: it's ok to catch www.gr such stuff exist!
|
# NOTE: it's ok to catch www.gr such stuff exist!
|
||||||
|
|
||||||
#FIXME: recognize xmpp: and treat it specially
|
#FIXME: recognize xmpp: and treat it specially
|
||||||
|
@ -2295,7 +2295,7 @@ class Interface:
|
||||||
|
|
||||||
latex = r'|\$\$[^$\\]*?([\]\[0-9A-Za-z()|+*/-]|[\\][\]\[0-9A-Za-z()|{}$])(.*?[^\\])?\$\$'
|
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'):
|
if gajim.config.get('use_latex'):
|
||||||
basic_pattern += latex
|
basic_pattern += latex
|
||||||
|
|
Loading…
Reference in New Issue