Class: Markbridge::Parsers::BBCode::RawContentCollector

Inherits:
Object
  • Object
show all
Defined in:
lib/markbridge/parsers/bbcode/raw_content_collector.rb

Overview

Strategy for collecting raw unparsed content between BBCode tags

Instance Method Summary collapse

Instance Method Details

#collect(tag_name, scanner) ⇒ RawContentResult

Collect raw unparsed content between BBCode tags

Parameters:

  • tag_name (String)

    the tag to match

  • scanner (Scanner)

    the token source

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/markbridge/parsers/bbcode/raw_content_collector.rb', line 12

def collect(tag_name, scanner)
  depth = 1
  content = +""
  closed = false

  while (token = scanner.next_token)
    if token.is_a?(TagStartToken) && token.tag == tag_name
      depth += 1
    elsif token.is_a?(TagEndToken) && token.tag == tag_name
      if (depth -= 1) == 0
        closed = true
        break
      end
    end

    content << token.source
  end

  RawContentResult.new(content:, closed:)
end