def self.next_item_list(reader, list_type, parent)
list_block = List.new(parent, list_type)
if parent.context == list_type
list_block.level = parent.level + 1
else
list_block.level = 1
end
while reader.has_more_lines? && (match = ListRxMap[list_type].match(reader.peek_line))
marker = resolve_list_marker(list_type, match[1])
if list_block.items? && marker != list_block.items[0].marker
this_item_level = list_block.level + 1
ancestor = parent
while ancestor.context == list_type
if marker == ancestor.items[0].marker
this_item_level = ancestor.level
break
end
ancestor = ancestor.parent
end
else
this_item_level = list_block.level
end
if !list_block.items? || 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
list_block.items[-1] << next_block(reader, list_block)
end
list_block << list_item if list_item
list_item = nil
reader.skip_blank_lines || break
end
list_block
end