def self.next_list_item(reader, list_block, match, sibling_trait = nil)
if (list_type = list_block.context) == :dlist
list_term = ListItem.new(list_block, match[1])
list_item = ListItem.new(list_block, match[3])
has_text = !match[3].nil_or_empty?
else
text = match[2]
checkbox = false
if list_type == :ulist && text.start_with?('[')
if text.start_with?('[ ] ')
checkbox = true
checked = false
text = text[3..-1].lstrip
elsif text.start_with?('[x] ', '[*] ')
checkbox = true
checked = true
text = text[3..-1].lstrip
end
end
list_item = ListItem.new(list_block, text)
if checkbox
list_block.attributes['checklist-option'] = ''
list_item.attributes['checkbox'] = ''
list_item.attributes['checked'] = '' if checked
end
sibling_trait ||= resolve_list_marker(list_type, match[1], list_block.items.size, true, reader)
list_item.marker = sibling_trait
has_text = true
end
reader.shift
list_item_reader = Reader.new read_lines_for_list_item(reader, list_type, sibling_trait, has_text), reader.cursor
if list_item_reader.has_more_lines?
comment_lines = list_item_reader.skip_line_comments
if (subsequent_line = list_item_reader.peek_line)
list_item_reader.unshift_lines comment_lines unless comment_lines.empty?
if (continuation_connects_first_block = subsequent_line.empty?)
content_adjacent = false
else
content_adjacent = true
has_text = false unless list_type == :dlist
end
else
continuation_connects_first_block = false
content_adjacent = false
end
options = {:text => !has_text}
while ((block = next_block list_item_reader, list_item, {}, options) && list_item << block) ||
list_item_reader.has_more_lines?
end
list_item.fold_first(continuation_connects_first_block, content_adjacent)
end
if list_type == :dlist
if list_item.text? || list_item.blocks?
[list_term, list_item]
else
[list_term, nil]
end
else
list_item
end
end