Class: Markbridge::Processors::DiscourseMarkdown::Scanner
- Inherits:
-
Object
- Object
- Markbridge::Processors::DiscourseMarkdown::Scanner
- Defined in:
- lib/markbridge/processors/discourse_markdown/scanner.rb
Overview
Single-pass scanner for Discourse Markdown that extracts specific constructs (mentions, polls, events, uploads) while preserving all other content unchanged.
The scanner respects code blocks (fenced, indented, and inline) and will not extract constructs that appear within code.
Constant Summary collapse
- DEFAULT_DETECTORS =
Default detectors in priority order
[ Detectors::Poll, Detectors::Event, Detectors::Upload, Detectors::Mention, ].freeze
- TRIGGER_CHARS =
Characters that can start a construct (for fast bailout)
Set.new(["@", "[", "!"]).freeze
Instance Method Summary collapse
-
#initialize(detectors: DEFAULT_DETECTORS, tag_library: nil, mention_resolver: nil) ⇒ Scanner
constructor
A new instance of Scanner.
-
#scan(input) ⇒ ScanResult
Scan input and extract constructs.
Constructor Details
#initialize(detectors: DEFAULT_DETECTORS, tag_library: nil, mention_resolver: nil) ⇒ Scanner
Returns a new instance of Scanner.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/markbridge/processors/discourse_markdown/scanner.rb', line 49 def initialize(detectors: DEFAULT_DETECTORS, tag_library: nil, mention_resolver: nil) @detector_instances = build_detectors(detectors, mention_resolver) @tag_library = tag_library @code_tracker = nil @result = nil @nodes = nil @node_index = 0 @pos = 0 @input = nil @line_start = true end |
Instance Method Details
#scan(input) ⇒ ScanResult
Scan input and extract constructs.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/markbridge/processors/discourse_markdown/scanner.rb', line 65 def scan(input) return ScanResult.new(markdown: "", nodes: []) if input.nil? || input.empty? @code_tracker = CodeBlockTracker.new @result = +"" @nodes = [] @node_index = 0 @pos = 0 @input = input @line_start = true scan_input ScanResult.new(markdown: @result, nodes: @nodes) end |