def self.next_outline_list(reader, list_type, parent)
list_block = Block.new(parent, list_type)
items = []
list_block.buffer = items
if parent.context == list_type
list_block.level = parent.level + 1
else
list_block.level = 1
end
Debug.debug { "Created #{list_type} block: #{list_block}" }
while reader.has_more_lines? && (match = reader.peek_line.match(REGEXP[list_type]))
marker = resolve_list_marker(list_type, match[1])
if items.size > 0 && marker != items.first.marker
this_item_level = list_block.level + 1
p = parent
while p.context == list_type
if marker == p.buffer.first.marker
this_item_level = p.level
break
end
p = p.parent
end
else
this_item_level = list_block.level
end
if items.size == 0 || this_item_level == list_block.level
list_item = next_list_item(reader, list_block, match)
elsif this_item_level < list_block.level
break
elsif this_item_level > list_block.level
items.last.blocks << next_block(reader, list_block)
end
items << list_item unless list_item.nil?
list_item = nil
reader.skip_blank_lines
end
list_block
end