From bbdf1919316f3820a7b3bc498965abe29081c5a0 Mon Sep 17 00:00:00 2001 From: Tom Theisen Date: Tue, 24 Apr 2018 21:19:14 -0700 Subject: [PATCH 1/2] handle escaped pipes in gfm tables --- lib/marked.js | 21 +++++++++++++++------ test/specs/gfm/gfm-spec.js | 3 +-- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 1fe8ba45ac..dd6ab13523 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -249,7 +249,7 @@ Lexer.prototype.token = function(src, top) { item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), cells: cap[3].replace(/\n$/, '').split('\n') }; @@ -267,7 +267,7 @@ Lexer.prototype.token = function(src, top) { } for (i = 0; i < item.cells.length; i++) { - item.cells[i] = item.cells[i].split(/ *\| */); + item.cells[i] = splitCells(item.cells[i]); } this.tokens.push(item); @@ -416,7 +416,7 @@ Lexer.prototype.token = function(src, top) { item = { type: 'table', - header: cap[1].replace(/^ *| *\| *$/g, '').split(/ *\| */), + header: splitCells(cap[1].replace(/^ *| *\| *$/g, '')), align: cap[2].replace(/^ *|\| *$/g, '').split(/ *\| */), cells: cap[3].replace(/(?: *\| *)?\n$/, '').split('\n') }; @@ -434,9 +434,8 @@ Lexer.prototype.token = function(src, top) { } for (i = 0; i < item.cells.length; i++) { - item.cells[i] = item.cells[i] - .replace(/^ *\| *| *\| *$/g, '') - .split(/ *\| */); + item.cells[i] = splitCells( + item.cells[i].replace(/^ *\| *| *\| *$/g, '')); } this.tokens.push(item); @@ -1311,6 +1310,16 @@ function merge(obj) { return obj; } +function splitCells(tableRow) { + var cells = tableRow.replace(/([^\\])\|/g, "$1 |").split(/ +\| */), + i = 0; + + for (; i < cells.length; i++) { + cells[i] = cells[i].replace(/\\\|/g, "|"); + } + return cells; +} + /** * Marked */ diff --git a/test/specs/gfm/gfm-spec.js b/test/specs/gfm/gfm-spec.js index a91b5396d2..3589a5f3e5 100644 --- a/test/specs/gfm/gfm-spec.js +++ b/test/specs/gfm/gfm-spec.js @@ -28,8 +28,7 @@ var messenger = new Messenger(); describe('GFM 0.28 Tables', function() { var section = 'Tables'; - // TODO: Verify exmaple 193 is valid and passing - var shouldPassButFails = [192, 193, 195, 196, 197]; + var shouldPassButFails = [192, 195, 196, 197]; var willNotBeAttemptedByCoreTeam = []; From e4973edfed540f6284944274fc15bf094e47461c Mon Sep 17 00:00:00 2001 From: Tom Theisen Date: Tue, 24 Apr 2018 21:20:10 -0700 Subject: [PATCH 2/2] lint --- lib/marked.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index dd6ab13523..55b06b4aff 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1311,11 +1311,11 @@ function merge(obj) { } function splitCells(tableRow) { - var cells = tableRow.replace(/([^\\])\|/g, "$1 |").split(/ +\| */), + var cells = tableRow.replace(/([^\\])\|/g, '$1 |').split(/ +\| */), i = 0; for (; i < cells.length; i++) { - cells[i] = cells[i].replace(/\\\|/g, "|"); + cells[i] = cells[i].replace(/\\\|/g, '|'); } return cells; }