Class: Markbridge::Processors::DiscourseMarkdown::Detectors::Event
- Defined in:
- lib/markbridge/processors/discourse_markdown/detectors/event.rb
Overview
Detects Discourse event blocks [event]….
Constant Summary collapse
- OPEN_TAG_PATTERN =
/\[event(?<attrs>[^\]]*)\]/i- CLOSE_TAG_PATTERN =
%r{\[/event\]}i
Instance Method Summary collapse
-
#detect(input, pos) ⇒ Match?
Attempt to detect an event at the given position.
Instance Method Details
#detect(input, pos) ⇒ Match?
Attempt to detect an event at the given position.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/event.rb', line 23 def detect(input, pos) remaining = input[pos..] open_match = OPEN_TAG_PATTERN.match(remaining) return nil unless open_match&.begin(0)&.zero? # Find closing tag. The opening tag pattern forbids `]` between # `[event` and its closing `]`, so `[/event]` cannot appear inside # the opening tag - no need to skip past it. close_match = CLOSE_TAG_PATTERN.match(remaining) return nil unless close_match # Extract raw content end_pos = pos + close_match.end(0) raw = input[pos...end_pos] # Parse attributes from opening tag attrs = parse_attributes(open_match[:attrs]) # Validate required attributes name = attrs["name"] starts_at = attrs["start"] return nil if name.nil? || starts_at.nil? node = AST::Event.new( name:, starts_at:, ends_at: attrs["end"], status: attrs["status"], timezone: attrs["timezone"], raw:, ) Match.new(start_pos: pos, end_pos:, node:) end |