lib/kramdown/parser/kramdown/table.rb in kramdown-0.10.0 vs lib/kramdown/parser/kramdown/table.rb in kramdown-0.11.0

- old
+ new

@@ -18,29 +18,30 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. #++ # -require 'kramdown/parser/kramdown/blank_line' -require 'kramdown/parser/kramdown/eob' -require 'kramdown/parser/kramdown/horizontal_rule' +require 'kramdown/parser/kramdown/block_boundary' module Kramdown module Parser class Kramdown - TABLE_SEP_LINE = /^#{OPT_SPACE}(?:\||\+)([ ]?:?-[+|: -]*)[ \t]*\n/ + TABLE_SEP_LINE = /^([+|: -]*?-[+|: -]*?)[ \t]*\n/ TABLE_HSEP_ALIGN = /[ ]?(:?)-+(:?)[ ]?/ - TABLE_FSEP_LINE = /^#{OPT_SPACE}(\||\+)[ ]?:?=[+|: =]*[ \t]*\n/ - TABLE_ROW_LINE = /^#{OPT_SPACE}\|(.*?)[ \t]*\n/ - TABLE_START = /^#{OPT_SPACE}\|(?:-|(?!=))/ + TABLE_FSEP_LINE = /^[+|: =]*?=[+|: =]*?[ \t]*\n/ + TABLE_ROW_LINE = /^(.*?)[ \t]*\n/ + TABLE_LINE = /(?:\||.*?[^\\\n]\|).*?\n/ + TABLE_START = /^#{OPT_SPACE}(?=\S)#{TABLE_LINE}/ # Parse the table at the current location. def parse_table - orig_pos = @src.pos - table = new_block_el(:table, nil, :alignment => []) + return false if !after_block_boundary? + orig_pos = @src.pos + table = new_block_el(:table, nil, nil, :alignment => []) + leading_pipe = (@src.check(TABLE_LINE) =~ /^\s*\|/) @src.scan(TABLE_SEP_LINE) rows = [] has_footer = false columns = 0 @@ -52,10 +53,11 @@ table.children << cont end end while !@src.eos? + break if !@src.check(TABLE_LINE) if @src.scan(TABLE_SEP_LINE) && !rows.empty? if table.options[:alignment].empty? && !has_footer add_container.call(:thead, false) table.options[:alignment] = @src[1].scan(TABLE_HSEP_ALIGN).map do |left, right| (left.empty? && right.empty? && :default) || (right.empty? && :left) || (left.empty? && :right) || :center @@ -77,10 +79,11 @@ cells.delete_at(i+1) else i += 1 end end + cells.shift if leading_pipe && cells.first.strip.empty? cells.pop if cells.last.strip.empty? cells.each do |cell_text| tcell = Element.new(:td) tcell.children << Element.new(:raw_text, cell_text.strip) trow.children << tcell @@ -88,9 +91,14 @@ columns = [columns, cells.length].max rows << trow else break end + end + + if !before_block_boundary? + @src.pos = orig_pos + return false end add_container.call(has_footer ? :tfoot : :tbody, false) if !rows.empty? if !table.children.any? {|c| c.type == :tbody}