'@username' matching implemented

main
Inga 🏳‍🌈 13 years ago
parent a1b2bf6d72
commit 7e0e55b9c1
  1. 9
      FLocal.Common/UBBParser.cs

@ -69,6 +69,14 @@ namespace FLocal.Common {
return BBCodes.UrlProcessor.ProcessLink(url, null, true) + remainder; return BBCodes.UrlProcessor.ProcessLink(url, null, true) + remainder;
} }
private static readonly Regex USERS_MATCHER = new Regex("(?<start>^|\\W)@(?<username>\\w+)(?<end>\\W|$)", RegexOptions.Singleline | RegexOptions.Compiled);
private static string USERS_REPLACE(BBCodes.IPostParsingContext context, Match match) {
string start = match.Groups["start"].Value;
string username = match.Groups["username"].Value;
string end = match.Groups["end"].Value;
return start + BBCodes.UserMentionProcessor.ProcessUserMention(context, username) + end;
}
private static readonly Dictionary<Regex, MatchEvaluator> TYPOGRAPHICS = new Dictionary<Regex, MatchEvaluator> { private static readonly Dictionary<Regex, MatchEvaluator> TYPOGRAPHICS = new Dictionary<Regex, MatchEvaluator> {
{ new Regex("(?<=\\s)--?(?=\\s)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "–" }, { new Regex("(?<=\\s)--?(?=\\s)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "–" },
{ new Regex("(?<=\\s)---(?=\\s)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "—" }, { new Regex("(?<=\\s)---(?=\\s)", RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.Singleline), match => "—" },
@ -95,6 +103,7 @@ namespace FLocal.Common {
public string Format(BBCodes.IPostParsingContext context, string source) { public string Format(BBCodes.IPostParsingContext context, string source) {
string result = this.inner.Format(context, source).Replace("&nbsp;", " "); string result = this.inner.Format(context, source).Replace("&nbsp;", " ");
result = LINKS_MATCHER.Replace(result, LINKS_REPLACE); result = LINKS_MATCHER.Replace(result, LINKS_REPLACE);
result = USERS_MATCHER.Replace(result, match => USERS_REPLACE(context, match));
foreach(var smile in SMILEYS_DATA) { foreach(var smile in SMILEYS_DATA) {
result = smile.Key.Replace(result, smile.Value); result = smile.Key.Replace(result, smile.Value);
} }

Loading…
Cancel
Save