From 04736e99cac9969bd212bba7a2e8cd35e7ef1cd5 Mon Sep 17 00:00:00 2001 From: vitalyster Date: Tue, 9 Oct 2012 23:24:40 +0400 Subject: RichText: navigate to Juick entities --- Juick/Classes/RichTextConverter.cs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Juick/Classes') diff --git a/Juick/Classes/RichTextConverter.cs b/Juick/Classes/RichTextConverter.cs index cdc1938..4f78b96 100644 --- a/Juick/Classes/RichTextConverter.cs +++ b/Juick/Classes/RichTextConverter.cs @@ -11,6 +11,8 @@ namespace Juick.Classes public class RichTextConverter : IValueConverter { static readonly Regex UrlRegex = new Regex(@"http(s)?://([\w+?\.\w+])+([a-zA-Z0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?", RegexOptions.Compiled); + // TODO: Add more entities + static readonly Regex JuickEntityRegex = new Regex(@"#(\d+)(/\d+)?", RegexOptions.Compiled); public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { @@ -22,12 +24,13 @@ namespace Juick.Classes var result = new List(); var index = 0; - foreach (var match in UrlRegex.Matches(stringValue).Cast()) + foreach (var match in UrlRegex.Matches(stringValue).OfType().Union(JuickEntityRegex.Matches(stringValue).OfType())) { Uri uri = null; if (!Uri.TryCreate(match.Value, UriKind.Absolute, out uri)) { - continue; + // Juick entity + uri = new Uri(string.Format("/ThreadView.xaml?mid={0}", JuickEntityRegex.Replace(match.Value, "$1")), UriKind.Relative); } if (match.Index > 0) { @@ -40,10 +43,17 @@ namespace Juick.Classes var hyperLink = new Hyperlink { - NavigateUri = uri, - TargetName = "_blank" + NavigateUri = uri }; - hyperLink.Inlines.Add(uri.Host); + if (uri.IsAbsoluteUri) + { + hyperLink.TargetName = "_blank"; + hyperLink.Inlines.Add(uri.Host); + } + else + { + hyperLink.Inlines.Add(match.Value); + } result.Add(hyperLink); index = match.Index + match.Length; -- cgit v1.2.3