diff --git a/lib/kramed.js b/lib/kramed.js index 0c9ad61..48b9252 100644 --- a/lib/kramed.js +++ b/lib/kramed.js @@ -99,8 +99,8 @@ block.gfm.paragraph = replace(block.paragraph) */ block.tables = merge({}, block.gfm, { - nptable: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, - table: /^ *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ + nptable: /^(?: *\'\'\'\n(.*(?:\n.+)*)\n\'\'\'\n)? *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/, + table: /^(?: *\'\'\'\n(.*(?:\n.+)*)\n\'\'\'\n)? *\|(.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/ }); /** @@ -245,9 +245,10 @@ Lexer.prototype.token = function(src, top, bq) { item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3].replace(/\n$/, '').split('\n') + caption: cap[1], + header: cap[2].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[3].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[4].replace(/\n$/, '').split('\n') }; for (i = 0; i < item.align.length; i++) { @@ -416,9 +417,10 @@ Lexer.prototype.token = function(src, top, bq) { item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), - align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n').slice(0), + caption: cap[1], + header: cap[2].replace(/^ *| *\| *$/g, '').split(/ *\| */), + align: cap[3].replace(/^ *|\| *$/g, '').split(/ *\| */), + cells: cap[4].replace(/(?: *\| *)?\n$/, '').split('\n').slice(0), }; for (i = 0; i < item.align.length; i++) { @@ -895,8 +897,9 @@ Renderer.prototype.paragraph = function(text) { return '
' + text + '
\n'; }; -Renderer.prototype.table = function(header, body) { +Renderer.prototype.table = function(caption, header, body) { return '| Cell 5 | Cell 6 | Cell 7 | Cell 8 |
| Header 1 | Header 2 |
|---|---|
| Cell 1 | Cell 2 |
| Cell 3 | Cell 4 |