class Kramdown::Parser::Kramdown
def parse_list
def parse_list if @tree.children.last && @tree.children.last.type == :p # last element must not be a paragraph return false end type, list_start_re = (@src.check(LIST_START_UL) ? [:ul, LIST_START_UL] : [:ol, LIST_START_OL]) list = new_block_el(type) item = nil indent_re = nil content_re = nil eob_found = false nested_list_found = false while !@src.eos? if @src.check(HR_START) break elsif @src.scan(list_start_re) item = Element.new(:li) item.value, indentation, content_re, indent_re = parse_first_list_line(@src[1].length, @src[2]) list.children << item item.value.sub!(/^#{IAL_SPAN_START}/) do |match| parse_attribute_list($~[1], item.options[:ial] ||= {}) '' end list_start_re = (type == :ul ? /^( {0,#{[3, indentation - 1].min}}[+*-])([\t| ].*?\n)/ : /^( {0,#{[3, indentation - 1].min}}\d+\.)([\t| ].*?\n)/) nested_list_found = false elsif result = @src.scan(content_re) result.sub!(/^(\t+)/) { " "*4*($1 ? $1.length : 0) } result.sub!(indent_re, '') if !nested_list_found && result =~ LIST_START parse_blocks(item, item.value) if item.children.length == 1 && item.children.first.type == :p item.value = '' else item.children.clear end nested_list_found = true end item.value << result elsif result = @src.scan(BLANK_LINE) nested_list_found = true item.value << result elsif @src.scan(EOB_MARKER) eob_found = true break else break end end @tree.children << list last = nil list.children.each do |it| temp = Element.new(:temp) parse_blocks(temp, it.value) it.children += temp.children it.value = nil next if it.children.size == 0 if it.children.first.type == :p && (it.children.length < 2 || it.children[1].type != :blank || (it == list.children.last && it.children.length == 2 && !eob_found)) && (list.children.last != it || list.children.size == 1 || list.children[0..-2].any? {|cit| cit.children.first.type != :p}) text = it.children.shift.children.first text.value += "\n" if !it.children.empty? && it.children[0].type != :blank it.children.unshift(text) else it.options[:first_is_block] = true end if it.children.last.type == :blank last = it.children.pop else last = nil end end @tree.children << last if !last.nil? && !eob_found true end