From 13f61f068e611b7d0a92e5a31465e27ff338283b Mon Sep 17 00:00:00 2001 From: icm7216 Date: Fri, 18 Dec 2015 14:15:33 +0900 Subject: [PATCH] fix display table cell if it empty cell --- lib/marked.js | 5 ++++- test/new/gfm_tables.html | 31 +++++++++++++++++++++++++++++++ test/new/gfm_tables.text | 20 ++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 03251f3c58..d38114583e 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -385,7 +385,7 @@ Lexer.prototype.token = function(src, top, bq) { type: 'table', header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), - cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') + cells: cap[3].replace(/\n$/, '').split('\n') }; for (i = 0; i < item.align.length; i++) { @@ -401,6 +401,9 @@ Lexer.prototype.token = function(src, top, bq) { } for (i = 0; i < item.cells.length; i++) { + if (!item.cells[i].match(/\|$/)) { + item.cells[i] = item.cells[i] + "\|"; + } item.cells[i] = item.cells[i] .replace(/^ *\| *| *\| *$/g, '') .split(/ *\| */); diff --git a/test/new/gfm_tables.html b/test/new/gfm_tables.html index 70bec827e3..66a1a04530 100644 --- a/test/new/gfm_tables.html +++ b/test/new/gfm_tables.html @@ -35,3 +35,34 @@ Cell 5Cell 6Cell 7Cell 8 +

In the bottom right corner cell is empty.

+ + + + + + + + + +
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
Cell 9Cell 10Cell 11
+ + + + + + + + + +
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
Cell 9Cell 10Cell 11
+ + + + + + + + + +
Header 1Header 2Header 3Header 4
Cell 1Cell 2Cell 3Cell 4
Cell 5Cell 6Cell 7Cell 8
Cell 9Cell 10Cell 11
diff --git a/test/new/gfm_tables.text b/test/new/gfm_tables.text index 5fd6321c1d..b1a75fd414 100644 --- a/test/new/gfm_tables.text +++ b/test/new/gfm_tables.text @@ -19,3 +19,23 @@ Header 1|Header 2|Header 3|Header 4 :-------|:------:|-------:|-------- Cell 1 |Cell 2 |Cell 3 |Cell 4 *Cell 5*|Cell 6 |Cell 7 |Cell 8 + +In the bottom right corner cell is empty. + +| Header 1 | Header 2 | Header 3 | Header 4 | +| :------: | -------: | :------- | -------- | +| Cell 1 | Cell 2 | Cell 3 | Cell 4 | +| Cell 5 | Cell 6 | Cell 7 | Cell 8 | +| Cell 9 | Cell 10 | Cell 11 | | + +| Header 1 | Header 2 | Header 3 | Header 4 +| :------: | -------: | :------- | -------- +| Cell 1 | Cell 2 | Cell 3 | Cell 4 +| Cell 5 | Cell 6 | Cell 7 | Cell 8 +| Cell 9 | Cell 10 | Cell 11 | + +Header 1 | Header 2 | Header 3 | Header 4 +:------: | -------: | :------- | -------- +Cell 1 | Cell 2 | Cell 3 | Cell 4 +Cell 5 | Cell 6 | Cell 7 | Cell 8 +Cell 9 | Cell 10 | Cell 11 |