示例#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 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);
			}
		}
示例#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;
		}