class Kramdown::Parser::Kramdown

def parse_definition_list

Parse the ordered or unordered list at the current location.
def parse_definition_list
  children = @tree.children
  if !children.last || (children.length == 1 && children.last.type != :p ) ||
      (children.length >= 2 && children[-1].type != :p && (children[-1].type != :blank || children[-1].value != "\n" || children[-2].type != :p))
    return false
  end
  first_as_para = false
  deflist = new_block_el(:dl)
  para = @tree.children.pop
  if para.type == :blank
    para = @tree.children.pop
    first_as_para = true
  end
  para.children.first.value.split("\n").each do |term|
    el = Element.new(:dt)
    el.children << Element.new(:text, term)
    deflist.children << el
  end
  item = nil
  indent_re = nil
  content_re = nil
  def_start_re = DEFINITION_LIST_START
  while !@src.eos?
    if @src.scan(def_start_re)
      item = Element.new(:dd)
      item.options[:first_as_para] = first_as_para
      item.value, indentation, content_re, indent_re = parse_first_list_line(@src[1].length, @src[2])
      deflist.children << item
      def_start_re = /^( {0,#{[3, indentation - 1].min}}:)([\t| ].*?\n)/
      first_as_para = false
    elsif result = @src.scan(content_re)
      result.sub!(/^(\t+)/) { " "*4*($1 ? $1.length : 0) }
      result.sub!(indent_re, '')
      item.value << result
      first_as_para = false
    elsif result = @src.scan(BLANK_LINE)
      first_as_para = true
      item.value << result
    else
      break
    end
  end
  last = nil
  deflist.children.each do |it|
    next if it.type == :dt
    parse_blocks(it, it.value)
    it.value = nil
    next if it.children.size == 0
    if it.children.last.type == :blank
      last = it.children.pop
    else
      last = nil
    end
    if it.children.first.type == :p && !it.options.delete(:first_as_para)
      text = it.children.shift.children.first
      text.value += "\n" if !it.children.empty?
      it.children.unshift(text)
    else
      it.options[:first_is_block] = true
    end
  end
  if @tree.children.length >= 1 && @tree.children.last.type == :dl
    @tree.children[-1].children += deflist.children
  elsif @tree.children.length >= 2 && @tree.children[-1].type == :blank && @tree.children[-2].type == :dl
    @tree.children.pop
    @tree.children[-1].children += deflist.children
  else
    @tree.children << deflist
  end
  @tree.children << last if !last.nil?
  true
end