示例#1
0
        void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       256 /* max url length */,
                                       Note.TagTable.UrlTag);

            Buffer.RemoveTag(Note.TagTable.UrlTag, start, end);

            for (Match match = regex.Match(start.GetSlice(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                /*
                 * Logger.Log ("Highlighting url: '{0}' at offset {1}",
                 *   group,
                 *   group.Index);
                 */

                Gtk.TextIter start_cpy = start;
                start_cpy.ForwardChars(group.Index);

                end = start_cpy;
                end.ForwardChars(group.Length);

                Buffer.ApplyTag(Note.TagTable.UrlTag, start_cpy, end);
            }
        }
示例#2
0
        void ApplyUrlToBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            NoteBuffer.GetBlockExtents(ref start,
                                       ref end,
                                       256 /* max url length */,
                                       Note.TagTable.UrlTag);

            Buffer.RemoveTag(Note.TagTable.UrlTag, start, end);

            Gtk.TextIter searchiter = start;
            for (Match match = regex.Match(start.GetSlice(end));
                 match.Success;
                 match = match.NextMatch())
            {
                System.Text.RegularExpressions.Group group = match.Groups [1];

                /*
                 * Logger.Log ("Highlighting url: '{0}' at offset {1}",
                 *   group,
                 *   group.Index);
                 */

                // Use the ForwardSearch instead of group's Index to account for multibyte chars in the text.
                // We'll search using the exact match value within provided boundaries.
                Gtk.TextIter startiter, enditer;
                searchiter.ForwardSearch(group.Value, Gtk.TextSearchFlags.VisibleOnly, out startiter, out enditer, end);
                searchiter = enditer;

                Buffer.ApplyTag(Note.TagTable.UrlTag, startiter, enditer);
            }
        }
示例#3
0
        string GetUrl(Gtk.TextIter start, Gtk.TextIter end)
        {
            string url = start.GetSlice(end);

            // FIXME: Needed because the file match is greedy and
            // eats a leading space.
            url = url.Trim();

            // Simple url massaging.  Add to 'http://' to the front
            // of www.foo.com, 'mailto:' to [email protected], 'file://'
            // to /home/alex/foo.
            if (url.StartsWith("www."))
            {
                url = "http://" + url;
            }
            else if (url.StartsWith("/") &&
                     url.LastIndexOf("/") > 1)
            {
                url = "file://" + url;
            }
            else if (url.StartsWith("~/"))
            {
                url = "file://" +
                      Path.Combine(Environment.GetEnvironmentVariable("HOME"),
                                   url.Substring(2));
            }
            else if (Regex.IsMatch(url,
                                   @"^(?!(news|mailto|http|https|ftp|file|irc):).+@.{2,}$",
                                   RegexOptions.IgnoreCase))
            {
                url = "mailto:" + url;
            }

            return(url);
        }
示例#4
0
        void HighlightInBlock(Gtk.TextIter start, Gtk.TextIter end)
        {
            IList <TrieHit> hits = Manager.TitleTrie.FindMatches(start.GetSlice(end));

            foreach (TrieHit hit in hits)
            {
                DoHighlight(hit, start, end);
            }
        }