diff --git a/markdown.rb b/markdown.rb index 3be5015..cb3d380 100644 --- a/markdown.rb +++ b/markdown.rb @@ -79,7 +79,7 @@ module Markdown x.gsub(/^(?"+content+"" - } + }.gsub(/^\-{3,}/,"
#{code.gsub /[|#*`~_!\[]/,"\\\\\\0"}
"
}
super()
end
@@ -162,28 +162,56 @@ module Markdown
tables = []
cur_table = []
lines.each_with_index { |line,index|
- if (line.start_with? / *\|/) and (line.match /^ *\|.*\|/) then
- table_start = index
- table_column_count = line.count "|"
- cur_table.push (line.split "|")
- end
- if (table_start != -1) and (line.match /^ *\|([^\|]*\|){#{table_column_count-1}}$/) then
+ if (table_start != -1) and (line.match /^\s*\|([^\|]*\|){#{table_column_count-1}}$/) then
if (table_testline == -1) then
- if (line.match /^ *\|(\-*\|){#{table_column_count-1}}$/) then
+ if (line.match /^\s*\|(\-*\|){#{table_column_count-1}}$/) then
table_testline = 1
else
table_start = -1
cur_table = []
end
else
- cur_table.push (line.split "|")
+ cur_table.push (line.split("|").filter_map { |x| x.strip if x.match /\S+/ })
end
+ elsif (table_start != -1) then
+ obj = {table: cur_table, start: table_start, end: index}
+ tables.push(obj)
+ table_start = -1
+ cur_table = []
+ table_testline = -1
+ table_column_count = 0
+ end
+ if (table_start == -1) and (line.start_with? /\s*\|/ ) and (line.match /^\s*\|.*\|/) then
+ table_start = index
+ table_column_count = line.count "|"
+ cur_table.push (line.split("|").filter_map { |x| x.strip if x.match /\S+/ })
end
- puts cur_table
}
+ if cur_table != [] then
+ obj = {table: cur_table, start:table_start, end: lines.count-1}
+ tables.push(obj)
+ end
+ tables.reverse.each { |x|
+ lines[x[:start]..x[:end]] = (x[:table].map do |a2d|
+ (a2d.map { |x| (x.start_with? "#") ? "