mirror of
https://github.com/lempamo/Project-Unite.git
synced 2025-01-22 17:22:15 +00:00
Allow user mentions.
This commit is contained in:
parent
ef1360b873
commit
ebc74ab7e7
1 changed files with 20 additions and 0 deletions
|
@ -91,8 +91,28 @@ public static IHtmlString TopicLinkFor(this HtmlHelper hpr, string topicId)
|
|||
return hpr.ActionLink(topic.Subject, "ViewTopic", "Forum", new { id = topic.Discriminator }, null);
|
||||
}
|
||||
|
||||
public static string ResolveUserLinksInMarkdown(string mkdn)
|
||||
{
|
||||
string[] words = mkdn.Split(' ');
|
||||
foreach(var word in words)
|
||||
{
|
||||
if (word.StartsWith("@"))
|
||||
{
|
||||
string uname = word.Remove(0, 1);
|
||||
var db = new ApplicationDbContext();
|
||||
var user = db.Users.FirstOrDefault(x => x.DisplayName == uname);
|
||||
if(user != null)
|
||||
{
|
||||
mkdn = mkdn.Replace(word, $"[{word}(/Profiles/ViewProfile/{uname})");
|
||||
}
|
||||
}
|
||||
}
|
||||
return mkdn;
|
||||
}
|
||||
|
||||
public static IHtmlString Markdown(this HtmlHelper hpr, string md)
|
||||
{
|
||||
md = ResolveUserLinksInMarkdown(md);
|
||||
return hpr.Raw(CommonMark.CommonMarkConverter.Convert(hpr.Encode(md)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue