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|
starts = s.start_with? ':'
ends = s.end_with? ':'
if s.empty?
nil
elsif starts && ends
:center
elsif ends
:right
else
:left
end
end
align.pop if align[-1].nil?
num_columns = align.size
head.pop if head.size == num_columns + 1 && head[-1].al.size == 0
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."
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?
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
else
colspan = 1
row[currIdx] = md_el(:cell, parse_span(s))
currElem = row[currIdx]
currIdx += 1
end
end
num_columns = count_columns(row)
if num_columns == head.size + 1 && row[-1].al.size == 0
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."
return md_br
end
rows << row
end
rows.unshift(head)
md_el(:table, rows, { :align => align })
end