Skip to content

Instantly share code, notes, and snippets.

@TheNotary
Created March 14, 2013 22:44
Show Gist options
  • Save TheNotary/5165908 to your computer and use it in GitHub Desktop.
Save TheNotary/5165908 to your computer and use it in GitHub Desktop.
def process_text
@text.scan(/((\[ (\/)? (\w+) ((=[^\[\]]+) | (\s\w+=\w+)* | ([^\]]*))? \]) | ([^\[]+))/ix) do |tag_info|
@ti = TagInfo.new(tag_info, @defined_tags)
@ti.handle_unregistered_tags_as_text # if the tag isn't in the @defined_tags list, then treat it as text
return if !valid_element?
# Validation of tag succeeded, add to @tags_list and/or bbtree
if @ti.element_is_opening_tag?
element = {:is_tag => true, :tag => @ti[:tag].to_sym, :nodes => [] }
element[:params] = {:tag_param => @ti[:params][:tag_param]} if @ti.can_have_params? and @ti.has_params?
@bbtree_current_node[:nodes] << BBTree.new(element) unless element.nil? # FIXME: It can't be nil here... but can elsewhere
escalate_bbtree(element)
elsif @ti.element_is_text?
element = {:is_tag => false, :text => @ti.text }
if within_open_tag?
tag = @defined_tags[@bbtree_current_node[:tag]]
if tag[:require_between]
@bbtree_current_node[:between] = @ti[:text]
if candidate_for_using_between_as_param?
use_between_as_tag_param # Did not specify tag_param, so use between.
end
element = nil
end
end
@bbtree_current_node[:nodes] << BBTree.new(element) unless element.nil?
elsif @ti.element_is_closing_tag?
retrogress_bbtree
end
end
# if we're still expecting a closing tag and we've come to the end of the string... throw error
if expecting_a_closing_tag?
@errors = ["[#{@tags_list.to_sentence(RubyBBCode.to_sentence_bbcode_tags)}] not closed"]
return
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment