diff options
author | vitalyster | 2012-10-09 23:24:40 +0400 |
---|---|---|
committer | vitalyster | 2012-10-09 23:24:40 +0400 |
commit | 04736e99cac9969bd212bba7a2e8cd35e7ef1cd5 (patch) | |
tree | 0af58a02f6f0aff9373b3a7cbc133fe09df484b4 /Juick/Classes | |
parent | 9252e0da67df741fa9212269434087689fb3f01e (diff) |
RichText: navigate to Juick entities
Diffstat (limited to 'Juick/Classes')
-rw-r--r-- | Juick/Classes/RichTextConverter.cs | 20 |
1 files changed, 15 insertions, 5 deletions
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<Inline>();
var index = 0;
- foreach (var match in UrlRegex.Matches(stringValue).Cast<Match>())
+ foreach (var match in UrlRegex.Matches(stringValue).OfType<Match>().Union(JuickEntityRegex.Matches(stringValue).OfType<Match>()))
{
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;
|