Method: RubyBBCode::TagSifter#process_text

Defined in:
lib/ruby-bbcode-to-md/tag_sifter.rb

#process_textObject



21
22
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
59
60
# File 'lib/ruby-bbcode-to-md/tag_sifter.rb', line 21

def process_text
  regex_string = '((\[ (\/)? (\w+) ((=[^\[\]]+) | (\s\w+=\w+)* | ([^\]]*))? \]) | ([^\[]+))'
  @text.scan(/#{regex_string}/ix) do |tag_info|
    @ti = TagInfo.new(tag_info, @dictionary)
    
    @ti.handle_unregistered_tags_as_text  # if the tag isn't in the @dictionary list, then treat it as text
    handle_closing_tags_that_are_multi_as_text_if_it_doesnt_match_the_latest_opener_tag_on_the_stack
    
    return if !valid_element?
    
    case @ti.type   # Validation of tag succeeded, add to @bbtree.tags_list and/or bbtree
    when :opening_tag
      element = {:is_tag => true, :tag => @ti[:tag].to_sym, :definition => @ti.definition, :nodes => TagCollection.new }
      element[:params] = {:tag_param => get_formatted_element_params} if @ti.can_have_params? and @ti.has_params?
      @bbtree.build_up_new_tag(element)

      @bbtree.escalate_bbtree(element)
    when :text
      set_parent_tag_from_multi_tag_to_concrete! if @bbtree.current_node.definition && @bbtree.current_node.definition[:multi_tag] == true
      element = {:is_tag => false, :text => @ti.text }
      if within_open_tag?
        tag = @bbtree.current_node.definition
        if tag[:require_between]
          @bbtree.current_node[:between] = get_formatted_element_params
          if candidate_for_using_between_as_param?
            use_between_as_tag_param    # Did not specify tag_param, so use between text.
          end
          next  # don't add this node to @bbtree.current_node.children if we're within an open tag that requires_between (to be a param), and the between couldn't be used as a param... Yet it passed validation so the param must have been specified within the opening tag???
        end
      end
      @bbtree.build_up_new_tag(element)
    when :closing_tag
      @bbtree.retrogress_bbtree
    end
    
  end # end of scan loop
  
  validate_all_tags_closed_off   # TODO: consider automatically closing off all the tags... I think that's how the HTML 5 parser works too
  validate_stack_level_too_deep_potential
end