def self.build_block(block_context, content_model, terminator, parent, reader, attributes, options = {})
if content_model == :skip
skip_processing, parse_as_content_model = true, :simple
elsif content_model == :raw
skip_processing, parse_as_content_model = false, :simple
else
skip_processing, parse_as_content_model = false, 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 => skip_processing
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
block_reader = Reader.new reader.read_lines_until(:terminator => terminator, :skip_processing => skip_processing), reader.cursor
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
elsif content_model == :skip
return
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.key? 'title') && block.context != :admonition &&
(parent.document.attributes.key? %(#{block.context}-caption))
block.title = attributes.delete 'title'
block.assign_caption(attributes.delete 'caption')
end
parse_blocks block_reader, block if content_model == :compound
block
end