def self.build_block(block_context, content_model, terminator, parent, reader, attributes, options = {})
if content_model == :skip || content_model == :raw
skip_processing = content_model == :skip
parse_as_content_model = :simple
else
skip_processing = false
parse_as_content_model = content_model
end
if terminator.nil?
if parse_as_content_model == :verbatim
lines = reader.read_lines_until(:break_on_blank_lines => true, :break_on_list_continuation => true)
else
content_model = :simple if content_model == :compound
lines = read_paragraph_lines reader, false, :skip_line_comments => true, :skip_processing => true
end
block_reader = nil
elsif parse_as_content_model != :compound
lines = reader.read_lines_until(:terminator => terminator, :skip_processing => skip_processing)
block_reader = nil
elsif terminator == false
lines = nil
block_reader = reader
else
lines = nil
cursor = reader.cursor
block_reader = Reader.new reader.read_lines_until(:terminator => terminator, :skip_processing => skip_processing), cursor
end
if content_model == :skip
attributes.clear
return lines
end
if content_model == :verbatim
if (indent = attributes['indent'])
adjust_indentation! lines, indent, (attributes['tabsize'] || parent.document.attributes['tabsize'])
elsif (tab_size = (attributes['tabsize'] || parent.document.attributes['tabsize']).to_i) > 0
adjust_indentation! lines, nil, tab_size
end
end
if (extension = options[:extension])
attributes.delete('style')
if (block = extension.process_method[parent, block_reader || (Reader.new lines), attributes.dup])
attributes.replace block.attributes
if block.content_model == :compound && !(lines = block.lines).nil_or_empty?
content_model = :compound
block_reader = Reader.new lines
end
else
return
end
else
block = Block.new(parent, block_context, :content_model => content_model, :source => lines, :attributes => attributes)
end
if (attributes.has_key? 'title') && (block.document.attr? %(#{block.context}-caption))
block.title = attributes.delete 'title'
block.assign_caption attributes.delete('caption')
end
if content_model == :compound
parse_blocks block_reader, block
end
block
end