Class: Qiita::Markdown::Filters::GroupMention::MentionableNode
- Inherits:
-
Object
- Object
- Qiita::Markdown::Filters::GroupMention::MentionableNode
- Defined in:
- lib/qiita/markdown/filters/group_mention.rb
Constant Summary collapse
- GROUP_IDENTIFIER_PATTERN =
%r{ (?:^|\W) @((?>[a-z\d][a-z\d-]{2,31})) \/ ([A-Za-z\d][A-Za-z\d-]{0,14}[A-Za-z\d]) (?!\/) (?= \.+[ \t\W]| \.+$| [^0-9a-zA-Z_.]| $ ) }x
- IGNORED_ANCESTOR_ELEMENT_NAMES =
%w[ a blockquote code pre style ].freeze
Instance Method Summary collapse
- #groups ⇒ Array<Hash>
- #ignorable? ⇒ false, true
-
#initialize(node, group_mention_url_generator) ⇒ MentionableNode
constructor
A new instance of MentionableNode.
- #replaced_html ⇒ String
Constructor Details
#initialize(node, group_mention_url_generator) ⇒ MentionableNode
Returns a new instance of MentionableNode.
45 46 47 48 |
# File 'lib/qiita/markdown/filters/group_mention.rb', line 45 def initialize(node, group_mention_url_generator) @group_mention_url_generator = group_mention_url_generator @node = node end |
Instance Method Details
#groups ⇒ Array<Hash>
51 52 53 |
# File 'lib/qiita/markdown/filters/group_mention.rb', line 51 def groups @groups ||= [] end |
#ignorable? ⇒ false, true
56 57 58 |
# File 'lib/qiita/markdown/filters/group_mention.rb', line 56 def ignorable? !has_at_mark? || has_any_ignored_ancestor? || !replaced? end |
#replaced_html ⇒ String
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/qiita/markdown/filters/group_mention.rb', line 61 def replaced_html @replaced_html ||= html.gsub(GROUP_IDENTIFIER_PATTERN) do |string| team_url_name = ::Regexp.last_match(1) group_url_name = ::Regexp.last_match(2) group = { group_url_name: group_url_name, team_url_name: team_url_name } groups << group string.sub( "@#{team_url_name}/#{group_url_name}", %(<a href="#{@group_mention_url_generator.call(group)}">) + %(@#{team_url_name}/#{group_url_name}</a>), ) end end |