From 3138a69bdb2cd6128825727b72a7c5923ebf6257 Mon Sep 17 00:00:00 2001
From: inga-lovinde <52715130+inga-lovinde@users.noreply.github.com>
Date: Mon, 12 Jul 2010 15:47:44 +0000
Subject: [PATCH] Links parsing in UBBParser implemented
---
Builder/IISMainHandler/build.txt | 2 +-
Common/BBCodes/FUrl.cs | 7 +++++--
Common/BBCodes/Url.cs | 7 +++++--
Common/BBCodes/helpers/UrlProcessor.cs | 15 +++++++++++++++
Common/UBBParser.cs | 6 ++++++
5 files changed, 32 insertions(+), 5 deletions(-)
diff --git a/Builder/IISMainHandler/build.txt b/Builder/IISMainHandler/build.txt
index a5a504b..4c88dcf 100644
--- a/Builder/IISMainHandler/build.txt
+++ b/Builder/IISMainHandler/build.txt
@@ -1 +1 @@
-799
\ No newline at end of file
+805
\ No newline at end of file
diff --git a/Common/BBCodes/FUrl.cs b/Common/BBCodes/FUrl.cs
index a0aa190..dd77367 100644
--- a/Common/BBCodes/FUrl.cs
+++ b/Common/BBCodes/FUrl.cs
@@ -13,8 +13,11 @@ namespace FLocal.Common.BBCodes {
public override string Format(ITextFormatter formatter) {
string rawUrl = this.DefaultOrValue;
- Uri uri = new Uri(rawUrl);
- return "" + this.GetInnerHTML(formatter) + "";
+ string title = null;
+ if(rawUrl.ToLower() != this.InnerText.ToLower()) {
+ title = this.GetInnerHTML(formatter);
+ }
+ return UrlProcessor.ProcessLink(rawUrl, title, false);
}
}
diff --git a/Common/BBCodes/Url.cs b/Common/BBCodes/Url.cs
index 63aeb0a..e879572 100644
--- a/Common/BBCodes/Url.cs
+++ b/Common/BBCodes/Url.cs
@@ -13,8 +13,11 @@ namespace FLocal.Common.BBCodes {
public override string Format(ITextFormatter formatter) {
string rawUrl = this.DefaultOrValue;
- var urlInfo = UrlProcessor.Process(rawUrl);
- return "" + this.GetInnerHTML(formatter) + "";
+ string title = null;
+ if(rawUrl.ToLower() != this.InnerText.ToLower()) {
+ title = this.GetInnerHTML(formatter);
+ }
+ return UrlProcessor.ProcessLink(rawUrl, title, true);
}
}
diff --git a/Common/BBCodes/helpers/UrlProcessor.cs b/Common/BBCodes/helpers/UrlProcessor.cs
index 11f71f5..35ffcac 100644
--- a/Common/BBCodes/helpers/UrlProcessor.cs
+++ b/Common/BBCodes/helpers/UrlProcessor.cs
@@ -53,5 +53,20 @@ namespace FLocal.Common.BBCodes {
}
}
+ public static string ProcessLink(string link, string title, bool shortenRelative) {
+ if(title == null) {
+ title = link;
+ }
+ string url;
+ if(shortenRelative) {
+ var urlInfo = UrlProcessor.Process(link);
+ url = urlInfo.relativeUrl;
+ } else {
+ var urlInfo = new Uri(link);
+ url = urlInfo.ToString();
+ }
+ return "" + title + "";
+ }
+
}
}
diff --git a/Common/UBBParser.cs b/Common/UBBParser.cs
index c36357e..828bebf 100644
--- a/Common/UBBParser.cs
+++ b/Common/UBBParser.cs
@@ -48,6 +48,11 @@ namespace FLocal.Common {
}
}
+ private static readonly Regex LINKS_MATCHER = new Regex("https?://[^\\s\\[<]+", RegexOptions.Singleline | RegexOptions.Compiled);
+ private static string LINKS_REPLACE(Match match) {
+ return BBCodes.UrlProcessor.ProcessLink(match.Value, null, true);
+ }
+
private static readonly Dictionary TYPOGRAPHICS = new Dictionary {
{ new Regex("(\\s+)--?(\\s+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "–" + match.Groups[2] },
{ new Regex("(\\s+)---(\\s+)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => match.Groups[1] + "—" + match.Groups[2] },
@@ -69,6 +74,7 @@ namespace FLocal.Common {
public string Format(string source) {
string result = this.inner.Format(source).Replace(" ", " ");
+ result = LINKS_MATCHER.Replace(result, LINKS_REPLACE);
foreach(var smile in SMILEYS_DATA) {
result = smile.Key.Replace(result, smile.Value);
}