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
- TAG_PATTERN =
%r{\A\[poll(?<attrs>[^\]]*)\](?<content>.*?)\[/poll\]}im
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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/markbridge/processors/discourse_markdown/detectors/poll.rb', line 22 def detect(input, pos) match = TAG_PATTERN.match(input[pos..]) return nil unless match attrs = parse_attributes(match[:attrs]) node = AST::Poll.new( name: attrs["name"] || "poll", type: attrs["type"], results: attrs["results"], public: attrs["public"] == "true", chart_type: attrs["charttype"], options: (match[:content]), raw: match[0], ) Match.new(start_pos: pos, end_pos: pos + match.end(0), node:) end |