bug 9285; fix detection of URLs in Styled text editor

This commit is contained in:
prculley 2016-12-16 16:02:36 -06:00 committed by Nick Hall
parent fb6ed2ab53
commit a5ed1086d8

View File

@ -105,14 +105,15 @@ FORMAT_TOOLBAR = '''
FONT_SIZES = [8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22, FONT_SIZES = [8, 9, 10, 11, 12, 13, 14, 16, 18, 20, 22,
24, 26, 28, 32, 36, 40, 48, 56, 64, 72] 24, 26, 28, 32, 36, 40, 48, 56, 64, 72]
USERCHARS = "-A-Za-z0-9" USERCHARS = r"-\w"
PASSCHARS = "-A-Za-z0-9,?;.:/!%$^*&~\"#'" PASSCHARS = r"-\w,?;.:/!%$^*&~\"#'"
HOSTCHARS = "-A-Za-z0-9" HOSTCHARS = r"-\w"
PATHCHARS = "-A-Za-z0-9_$.+!*(),;:@&=?/~#%" PATHCHARS = r"-\w$.+!*(),;:@&=?/~#%"
#SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)" #SCHEME = "(news:|telnet:|nntp:|file:/|https?:|ftps?:|webcal:)"
SCHEME = "(file:/|https?:|ftps?:|webcal:)" SCHEME = "(file:/|https?:|ftps?:|webcal:)"
USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?" USER = "[" + USERCHARS + "]+(:[" + PASSCHARS + "]+)?"
URLPATH = "/[" + PATHCHARS + "]*[^]'.}>) \t\r\n,\\\"]" HOST = r"([-\w.]+|\[[0-9A-F:]+\])?"
URLPATH = "(/[" + PATHCHARS + "]*)?[^]'.:}> \t\r\n,\\\"]"
(GENURL, HTTP, MAIL, LINK) = list(range(4)) (GENURL, HTTP, MAIL, LINK) = list(range(4))
@ -546,14 +547,14 @@ class StyledTextEditor(Gtk.TextView):
self.textbuffer.create_tag('hyperlink', self.textbuffer.create_tag('hyperlink',
underline=Pango.Underline.SINGLE, underline=Pango.Underline.SINGLE,
foreground=self.linkcolor) foreground=self.linkcolor)
self.textbuffer.match_add(SCHEME + "//(" + USER + "@)?[" + self.textbuffer.match_add(SCHEME + "//(" + USER + "@)?" +
HOSTCHARS + ".]+" + "(:[0-9]+)?(" + HOST + "(:[0-9]+)?" +
URLPATH + ")?/?", GENURL) URLPATH, GENURL)
self.textbuffer.match_add("(www|ftp)[" + HOSTCHARS + "]*\\.[" + self.textbuffer.match_add(r"(www\.|ftp\.)[" + HOSTCHARS + r"]*\.[" +
HOSTCHARS + ".]+" + "(:[0-9]+)?(" + HOSTCHARS + ".]+" + "(:[0-9]+)?" +
URLPATH + ")?/?", HTTP) URLPATH, HTTP)
self.textbuffer.match_add("(mailto:)?[a-z0-9][a-z0-9.-]*@[a-z0-9]" self.textbuffer.match_add(r"(mailto:)?[\w][-.\w]*@[\w]"
"[a-z0-9-]*(\\.[a-z0-9][a-z0-9-]*)+", MAIL) r"[-\w]*(\.[\w][-.\w]*)+", MAIL)
def _create_spell_menu(self): def _create_spell_menu(self):
""" """