Class: Markbridge::Processors::DiscourseMarkdown::Detectors::Mention
- Defined in:
- lib/markbridge/processors/discourse_markdown/detectors/mention.rb
Overview
Detects user and group mentions (@username, @groupname).
Instance Method Summary collapse
-
#detect(input, pos) ⇒ Match?
Attempt to detect a mention at the given position.
-
#initialize(type_resolver: nil) ⇒ Mention
constructor
A new instance of Mention.
Constructor Details
#initialize(type_resolver: nil) ⇒ Mention
Returns a new instance of Mention.
22 23 24 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/mention.rb', line 22 def initialize(type_resolver: nil) @type_resolver = type_resolver end |
Instance Method Details
#detect(input, pos) ⇒ Match?
Attempt to detect a mention at the given position.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/mention.rb', line 31 def detect(input, pos) return nil unless input[pos] == "@" return nil unless word_boundary?(input, pos) # Extract the username/group name name = extract_word(input, pos + 1) return nil if name.empty? end_pos = pos + 1 + name.length type = resolve_type(name) node = AST::Mention.new(name:, type:) Match.new(start_pos: pos, end_pos:, node:) end |