diff --git a/lib/marked.js b/lib/marked.js index 83a7de57ee..722da1c19d 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -15,6 +15,7 @@ var block = { code: /^( {4}[^\n]+\n*)+/, fences: noop, hr: /^( *[-*_]){3,} *(?:\n+|$)/, + table: /^(([^|]+\|)+[^\n]*){2,}/, heading: /^ *(#{1,6}) *([^\n]+?) *#* *(?:\n+|$)/, nptable: noop, lheading: /^([^\n]+)\n *(=|-){3,} *\n*/, @@ -197,6 +198,41 @@ Lexer.prototype.token = function(src, top, bq) { continue; } + // table + if (cap = block.table.exec(src)) { + src = src.substring(cap[0].length); + + tokens.push({ + type: 'table_start' + }); + + var rows = cap[0].split(/\n+ *-+ *\n+/); + rows.forEach(function(row) { + tokens.push({ + type: 'row_start' + }); + + var cols = row.split(' | '); + cols.forEach(function(col) { + //tokens.push({ + // type: 'cell', // or paragraph + // text: col + //}); + block.token(col, tokens, top); + }); + + tokens.push({ + type: 'row_end' + }); + }); + + tokens.push({ + type: 'table_end' + }); + + continue; + } + // heading if (cap = this.rules.heading.exec(src)) { src = src.substring(cap[0].length); @@ -1256,6 +1292,31 @@ Parser.prototype.tok = function() { : this.token.text; return this.renderer.html(html); } + case 'table_start': { + var body = ''; + while (next().type !== 'table_end') { + body += tok(); + } + return '