class Kramdown::Parser::Html::ElementConverter
def is_simple_table?(el)
def is_simple_table?(el) only_phrasing_content = lambda do |c| c.children.all? do |cc| (cc.type == :text || !HTML_BLOCK_ELEMENTS.include?(cc.value)) && only_phrasing_content.call(cc) end end check_cells = Proc.new do |c| if c.value == 'th' || c.value == 'td' return false if !only_phrasing_content.call(c) else c.children.each {|cc| check_cells.call(cc)} end end check_cells.call(el) nr_cells = 0 check_nr_cells = lambda do |t| if t.value == 'tr' count = t.children.select {|cc| cc.value == 'th' || cc.value == 'td'}.length if count != nr_cells if nr_cells == 0 nr_cells = count else nr_cells = -1 break end end else t.children.each {|cc| check_nr_cells.call(cc)} end end check_nr_cells.call(el) return false if nr_cells == -1 alignment = nil check_alignment = Proc.new do |t| if t.value == 'tr' cur_alignment = t.children.select {|cc| cc.value == 'th' || cc.value == 'td'}.map do |cell| md = /text-align:\s+(center|left|right|justify|inherit)/.match(cell.attr['style'].to_s) return false if md && (md[1] == 'justify' || md[1] == 'inherit') md.nil? ? :default : md[1] end alignment = cur_alignment if alignment.nil? return false if alignment != cur_alignment else t.children.each {|cc| check_alignment.call(cc)} end end check_alignment.call(el) check_rows = lambda do |t, type| t.children.all? {|r| (r.value == 'tr' || r.type == :text) && r.children.all? {|c| c.value == type || c.type == :text}} end check_rows.call(el, 'td') || (el.children.all? do |t| t.type == :text || (t.value == 'thead' && check_rows.call(t, 'th')) || ((t.value == 'tfoot' || t.value == 'tbody') && check_rows.call(t, 'td')) end && el.children.any? {|t| t.value == 'tbody'}) end