public override MarkdownNode VisitMention(MentionNode mention)
        {
            if (mention.Type == MentionType.Meta)
            {
                _buffer.Append($"@{mention.Id}");
            }
            else if (mention.Type == MentionType.User)
            {
                var member = _context.TryGetMentionedMember(mention.Id);
                var name   = member?.User.Name ?? "Unknown";

                _buffer.Append($"@{name}");
            }
            else if (mention.Type == MentionType.Channel)
            {
                var channel = _context.TryGetMentionedChannel(mention.Id);
                var name    = channel?.Name ?? "deleted-channel";

                _buffer.Append($"#{name}");
            }
            else if (mention.Type == MentionType.Role)
            {
                var role = _context.TryGetMentionedRole(mention.Id);
                var name = role?.Name ?? "deleted-role";

                _buffer.Append($"@{name}");
            }

            return(base.VisitMention(mention));
        }
Beispiel #2
0
        public override MarkdownNode VisitMention(MentionNode mention)
        {
            if (mention.Type == MentionType.Meta)
            {
                _buffer
                .Append("<span class=\"mention\">")
                .Append("@").Append(HtmlEncode(mention.Id))
                .Append("</span>");
            }
            else if (mention.Type == MentionType.User)
            {
                var member   = _context.TryGetMentionedMember(mention.Id);
                var fullName = member?.User.FullName ?? "Unknown";
                var nick     = member?.Nick ?? "Unknown";

                _buffer
                .Append($"<span class=\"mention\" title=\"{HtmlEncode(fullName)}\">")
                .Append("@").Append(HtmlEncode(nick))
                .Append("</span>");
            }
            else if (mention.Type == MentionType.Channel)
            {
                var channel = _context.TryGetMentionedChannel(mention.Id);
                var name    = channel?.Name ?? "deleted-channel";

                _buffer
                .Append("<span class=\"mention\">")
                .Append("#").Append(HtmlEncode(name))
                .Append("</span>");
            }
            else if (mention.Type == MentionType.Role)
            {
                var role  = _context.TryGetMentionedRole(mention.Id);
                var name  = role?.Name ?? "deleted-role";
                var color = role?.Color;

                var style = color != null
                    ? $"color: rgb({color?.R}, {color?.G}, {color?.B}); background-color: rgba({color?.R}, {color?.G}, {color?.B}, 0.1);"
                    : "";

                _buffer
                .Append($"<span class=\"mention\" style=\"{style}\">")
                .Append("@").Append(HtmlEncode(name))
                .Append("</span>");
            }

            return(base.VisitMention(mention));
        }