Links parsing in UBBParser implemented

main
Inga 🏳‍🌈 15 years ago
parent 00ab6640eb
commit 3138a69bdb
  1. 2
      Builder/IISMainHandler/build.txt
  2. 7
      Common/BBCodes/FUrl.cs
  3. 7
      Common/BBCodes/Url.cs
  4. 15
      Common/BBCodes/helpers/UrlProcessor.cs
  5. 6
      Common/UBBParser.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 "<a href=\"" + uri.ToString() + "\">" + this.GetInnerHTML(formatter) + "</a>";
string title = null;
if(rawUrl.ToLower() != this.InnerText.ToLower()) {
title = this.GetInnerHTML(formatter);
}
return UrlProcessor.ProcessLink(rawUrl, title, false);
}
}

@ -13,8 +13,11 @@ namespace FLocal.Common.BBCodes {
public override string Format(ITextFormatter formatter) {
string rawUrl = this.DefaultOrValue;
var urlInfo = UrlProcessor.Process(rawUrl);
return "<a href=\"" + urlInfo.relativeUrl + "\">" + this.GetInnerHTML(formatter) + "</a>";
string title = null;
if(rawUrl.ToLower() != this.InnerText.ToLower()) {
title = this.GetInnerHTML(formatter);
}
return UrlProcessor.ProcessLink(rawUrl, title, true);
}
}

@ -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 "<a href=\"" + url + "\">" + title + "</a>";
}
}
}

@ -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<Regex, MatchEvaluator> TYPOGRAPHICS = new Dictionary<Regex, MatchEvaluator> {
{ 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("&nbsp;", " ");
result = LINKS_MATCHER.Replace(result, LINKS_REPLACE);
foreach(var smile in SMILEYS_DATA) {
result = smile.Key.Replace(result, smile.Value);
}

Loading…
Cancel
Save