Method: HTML::Pipeline::MentionFilter#mention_link_filter

Defined in:
lib/html/pipeline/@mention_filter.rb

Replace user @mentions in text with links to the mentioned user’s profile page.

text - String text to replace @mention usernames in. base_url - The base URL used to construct user profile URLs. info_url - The “more info” URL used to link to more info on @mentions.

If nil we don't link @mention or @mentioned.

username_pattern - Regular expression used to identify usernames in

text

Returns a string with @mentions replaced with links. All links have a ‘user-mention’ class name attached for styling.



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/html/pipeline/@mention_filter.rb', line 106

def mention_link_filter(text, _base_url = '/', info_url = nil, username_pattern = UsernamePattern)
  self.class.mentioned_logins_in(text, username_pattern) do |match, , is_mentioned|
    link =
      if is_mentioned
        link_to_mention_info(, info_url)
      else
        link_to_mentioned_user()
      end

    link ? match.sub("@#{login}", link) : match
  end
end