Class: Qiita::Markdown::Filters::Mention

Inherits:
HTML::Pipeline::MentionFilter
  • Object
show all
Defined in:
lib/qiita/markdown/filters/mention.rb

Overview

  1. Adds :mentioned_usernames into result Hash as Array of String.

  2. Replaces @mention with link.

You can pass :allowed_usernames context to limit mentioned usernames.

Constant Summary collapse

MentionPattern =
/
  (?:^|\W)
  @((?>[\w][\w-]{1,30}\w(?:@github)?))
  (?!\/)
  (?=
    \.+[ \t\W]|
    \.+$|
    [^0-9a-zA-Z_.]|
    $
  )
/ix

Instance Method Summary collapse

Instance Method Details

Note:

Override to use customized MentionPattern and allowed_usernames logic.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/qiita/markdown/filters/mention.rb', line 22

def mention_link_filter(text, _, _)
  text.gsub(MentionPattern) do |match|
    name = $1
    if allowed_usernames && !allowed_usernames.include?(name)
      match
    else
      result[:mentioned_usernames] |= [name]
      url = File.join(base_url, name)
      match.sub(
        "@#{name}",
        %[<a href="#{url}" class="user-mention" title="#{name}">@#{name}</a>]
      )
    end
  end
end