diff options
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;
|