Class: Markbridge::Processors::DiscourseMarkdown::Detectors::Poll
- Defined in:
- lib/markbridge/processors/discourse_markdown/detectors/poll.rb
Overview
Detects Discourse poll blocks [poll]….
Constant Summary collapse
- OPEN_TAG_PATTERN =
/\[poll([^\]]*)\]/i- CLOSE_TAG_PATTERN =
%r{\[/poll\]}i
Instance Method Summary collapse
-
#detect(input, pos) ⇒ Match?
Attempt to detect a poll at the given position.
Instance Method Details
#detect(input, pos) ⇒ Match?
Attempt to detect a poll 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 58 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/poll.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]) # Extract options from content between tags content = remaining[open_match.end(0)...close_match.begin(0)] = (content) node = AST::Poll.new( name: attrs["name"] || "poll", type: attrs["type"], results: attrs["results"], public: attrs["public"] == "true", chart_type: attrs["charttype"] || attrs["chartType"], options:, raw:, ) Match.new(start_pos: pos, end_pos:, node:) end |