class HTMLPipeline::NodeFilter::TeamMentionFilter

HTML filter that replaces @org/team mentions with links. Mentions within <pre>, <code>, <a>, <style>, and <script> elements are ignored.

Context options:

:base_url - Used to construct links to team profile pages for each
            mention.
:team_pattern - Used to provide a custom regular expression to
                    identify team names

Constants

IGNORE_PARENTS

Don’t look for mentions in text nodes that are children of these elements

SELECTOR
TEAM_PATTERN

Default pattern used to extract team names from text. The value can be overridden by providing the team_pattern variable in the context. To properly link the mention, should be in the format of /@(1)/(2)/.

Public Class Methods

mentioned_teams_in(text, team_pattern = TEAM_PATTERN) { |match, org, team| ... } click to toggle source

Public: Find @org/team mentions in text. See TeamMentionFilter#team_mention_link_filter.

TeamMentionFilter.mentioned_teams_in(text) do |match, org, team|
  "<a href=...>#{team}</a>"
end

text - String text to search.

Yields the String match, org name, and team name. The yield’s return replaces the match in the original text.

Returns a String replaced with the return of the block.

# File lib/html_pipeline/node_filter/team_mention_filter.rb, line 31
def mentioned_teams_in(text, team_pattern = TEAM_PATTERN)
  text.gsub(team_pattern) do |match|
    org = Regexp.last_match(1)
    team = Regexp.last_match(2)
    yield match, org, team
  end
end

Public Instance Methods

after_initialize() click to toggle source
# File lib/html_pipeline/node_filter/team_mention_filter.rb, line 56
def after_initialize
  result[:mentioned_teams] = []
end
handle_text_chunk(text) click to toggle source
# File lib/html_pipeline/node_filter/team_mention_filter.rb, line 64
def handle_text_chunk(text)
  content = text.to_s
  return unless content.include?("@")

  text.replace(mention_link_filter(content, base_url: base_url, team_pattern: team_pattern), as: :html)
end
selector() click to toggle source
# File lib/html_pipeline/node_filter/team_mention_filter.rb, line 60
def selector
  SELECTOR
end
team_pattern() click to toggle source
# File lib/html_pipeline/node_filter/team_mention_filter.rb, line 71
def team_pattern
  context[:team_pattern] || TEAM_PATTERN
end