Class: PotMarkdown::Filters::MentionFilter

Inherits:
HTML::Pipeline::MentionFilter
  • Object
show all
Defined in:
lib/pot_markdown/filters/mention_filter.rb

Constant Summary collapse

USER_NAME_PATTERN =
/[A-Za-z0-9][A-Za-z0-9\-\_]+/

Instance Method Summary collapse

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/pot_markdown/filters/mention_filter.rb', line 9

def call
  result[:mentioned_usernames] ||= []

  doc.xpath('.//text()').each do |node|
    content = node.text
    next unless content.include?('@')
    next if has_ancestor?(node, IGNORE_PARENTS)
    html = mention_link_filter(content, base_url, info_url, username_pattern)
    next if html == content
    node.replace(html)
  end
  doc
end


27
28
29
30
# File 'lib/pot_markdown/filters/mention_filter.rb', line 27

def link_to_mentioned_user()
  result[:mentioned_usernames] |= []
  "<a href='#{base_url}#{}' class='user-mention'>@#{}</a>"
end

#username_patternObject



23
24
25
# File 'lib/pot_markdown/filters/mention_filter.rb', line 23

def username_pattern
  context[:username_pattern] || USER_NAME_PATTERN
end