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([^\]]*)\]/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 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/event.rb', line 23 def detect(input, pos) return nil unless input[pos] == "[" # Check for opening tag remaining = input[pos..] open_match = OPEN_TAG_PATTERN.match(remaining) return nil unless open_match&.begin(0)&.zero? # Find closing tag close_match = CLOSE_TAG_PATTERN.match(remaining, open_match.end(0)) 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[1]) # Validate required attributes return nil unless attrs["name"] && attrs["start"] node = AST::Event.new( name: attrs["name"], starts_at: attrs["start"], ends_at: attrs["end"], status: attrs["status"], timezone: attrs["timezone"], raw:, ) Match.new(start_pos: pos, end_pos:, node:) end |