# File lib/maruku/input/parse_block.rb, line 572
  def read_table(src)
    head = split_cells(src.shift_line).map do |s|
      md_el(:head_cell, parse_span(s))
    end

    separator = split_cells(src.shift_line)

    align = separator.map do |s|
      # ex: :-------------------:
      # If the separator starts and ends with a colon,
      # center the cell. If it's on the right, right-align,
      # otherwise left-align.
      starts = s.start_with? ':'
      ends = s.end_with? ':'
      if s.empty? # blank
        nil
      elsif starts && ends
        :center
      elsif ends
        :right
      else
        :left
      end
    end

    align.pop if align[-1].nil? # trailing blank
    num_columns = align.size

    head.pop if head.size == num_columns + 1 && head[-1].al.size == 0 # trailing blank

    if head.size != num_columns
      maruku_error "Table head does not have #{num_columns} columns: \n#{head.inspect}"
      tell_user "I will ignore this table."
      # XXX try to recover
      return md_br
    end

    rows = []
    while src.cur_line && src.cur_line.include?('|')
      row = []
      colCount = 0
      colspan = 1
      currElem = nil
      currIdx = 0
      split_cells(src.shift_line, true).map do |s|
        if s.empty?
          # empty cells increase the colspan of the previous cell
          found = false
          colspan +=  1
          al = (currElem &&currElem.al) || AttributeList.new
          if al.size > 0
            elem = find_colspan(al)
            if elem != nil
              elem[1] = colspan.to_s
              found = true
            end
          end
          al.push(["colspan", colspan.to_s]) unless found # also handles the case of and empty attribute list
        else
          colspan = 1
          row[currIdx] = md_el(:cell, parse_span(s))
          currElem = row[currIdx]
          currIdx += 1
        end
      end

      #
      # sanity check - make sure the current row has the right number of columns (including spans)
      #                If not, dump the table and return a break
      #
      num_columns = count_columns(row)
      if num_columns == head.size + 1 && row[-1].al.size == 0 #trailing blank cell
        row.pop
        num_columns -= 1
      end
      if head.size != num_columns
        maruku_error  "Row does not have #{head.size} columns: \n#{row.inspect} - #{num_columns}"
        tell_user "I will ignore this table."
        # XXX need to recover
        return md_br
      end
      rows << row
    end
    rows.unshift(head) # put the header row on the processed table
    md_el(:table, rows, { :align => align })
  end