Пример #1
0
    def detect_url(self, text: str, start: Gtk.TextIter) -> None:
        """Detect URLs and apply tags."""

        # Find all matches
        matches = url_regex.search(text)

        # Go through each with its own iterator and tag 'em
        for match in matches:
            url_start = start.copy()
            url_end = start.copy()

            url_start.forward_chars(match.start())
            url_end.forward_chars(match.end())

            url_tag = LinkTag(match.group(0))
            self.tags_applied.append(url_tag)

            self.table.add(url_tag)
            self.buffer.apply_tag(url_tag, url_start, url_end)
Пример #2
0
 def test_search_does_not_include_preceeding_whitespace(self):
     match = urlregex.search("This snippet contains an url with whitespace"
         "before it:  https://wiki.gnome.org/Apps/GTG/")
     self.assertEqual(list(match)[0].group(), "https://wiki.gnome.org/Apps/GTG/")