From e0f5edfa01569457ec2a24570c2b8b60dcb1706a Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 9 May 2018 16:19:59 -0500 Subject: [PATCH 1/8] add failing tests --- test/specs/marked/marked-spec.js | 15 +++++++++++++++ test/specs/marked/marked.json | 20 +++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/test/specs/marked/marked-spec.js b/test/specs/marked/marked-spec.js index 6a314273b1..5d4d32e91c 100644 --- a/test/specs/marked/marked-spec.js +++ b/test/specs/marked/marked-spec.js @@ -46,3 +46,18 @@ describe('Marked Code spans', function() { messenger.test(spec, section, ignore); }); }); + +describe('Marked Table cells', function() { + var section = 'Table cells'; + + // var shouldPassButFails = []; + var shouldPassButFails = []; + + var willNotBeAttemptedByCoreTeam = []; + + var ignore = shouldPassButFails.concat(willNotBeAttemptedByCoreTeam); + + markedSpec.forEach(function(spec) { + messenger.test(spec, section, ignore); + }); +}); diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index eedb65a83a..830a1a8cc3 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -2,7 +2,25 @@ { "section": "Code spans", "markdown": "`someone@example.com`", - "html": "

someone@exmaple.com

\n", + "html": "

someone@exmaple.com

", "example": 1 + }, + { + "section": "Table cells", + "markdown": "|1|\n|-|\n|\\\\\\\\||", + "html": "
1
\\\\
", + "example": 2 + }, + { + "section": "Table cells", + "markdown": "|1|\n|-|\n|\\\\\\\\\\||", + "html": "
1
\\\\|
", + "example": 3 + }, + { + "section": "Table cells", + "markdown": "|1|2|\n|-|-|\n||2|", + "html": "
12
2
", + "example": 4 } ] From 2c17a5a1ec4d192147ac7692cfb1606f063d2d4f Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 9 May 2018 16:27:30 -0500 Subject: [PATCH 2/8] test pass --- lib/marked.js | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 83974865e4..9a669655a1 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1340,7 +1340,20 @@ function merge(obj) { } function splitCells(tableRow, count) { - var cells = tableRow.replace(/([^\\])\|/g, '$1 |').split(/ +\| */), + var row = tableRow.replace(/\|/g, function (match, offset, str) { + var escaped = false, + curr = offset; + while (--curr >= 0 && str[curr] === '\\') escaped = !escaped; + if (escaped) { + // odd number of slashes means | is escaped + // so we leave it alone + return '|'; + } else { + // add space before unescaped | + return ' |'; + } + }), + cells = row.split(/ \|/), i = 0; if (cells.length > count) { @@ -1350,7 +1363,7 @@ function splitCells(tableRow, count) { } for (; i < cells.length; i++) { - cells[i] = cells[i].replace(/\\\|/g, '|'); + cells[i] = cells[i].trim().replace(/\\\|/g, '|'); } return cells; } From 450c33fbef79657c18295943f82db3af2647d015 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Wed, 9 May 2018 17:13:00 -0500 Subject: [PATCH 3/8] add test --- test/specs/marked/marked.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 830a1a8cc3..4f870f861e 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -22,5 +22,11 @@ "markdown": "|1|2|\n|-|-|\n||2|", "html": "
12
2
", "example": 4 + }, + { + "section": "Table cells", + "markdown": "|1|2|\n|-|-|\n|1\\|\\\\|2\\|\\\\|", + "html": "
12
1|\\2|\\
", + "example": 5 } ] From 6e81048a94427eaa2042602ed7cd37a3ee31c23b Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 4 Jun 2018 14:38:45 -0500 Subject: [PATCH 4/8] fix spelling --- test/specs/marked/marked.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 4f870f861e..262d91c66a 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -2,7 +2,7 @@ { "section": "Code spans", "markdown": "`someone@example.com`", - "html": "

someone@exmaple.com

", + "html": "

someone@example.com

", "example": 1 }, { From 96018d3177bd0d515222e043776467b566faefb1 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 4 Jun 2018 15:07:59 -0500 Subject: [PATCH 5/8] add simple tests --- test/specs/marked/marked.json | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 262d91c66a..e2ff694db1 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -5,28 +5,46 @@ "html": "

someone@example.com

", "example": 1 }, + { + "section": "Table cells", + "markdown": "|1|\n|-|\n|1|", + "html": "
1
1
", + "example": 2 + }, + { + "section": "Table cells", + "markdown": "|1|\n|-|\n|1\\||", + "html": "
1
1|
", + "example": 3 + }, + { + "section": "Table cells", + "markdown": "|1|\n|-|\n|1\\\\1|", + "html": "
1
1\\1
", + "example": 4 + }, { "section": "Table cells", "markdown": "|1|\n|-|\n|\\\\\\\\||", "html": "
1
\\\\
", - "example": 2 + "example": 5 }, { "section": "Table cells", "markdown": "|1|\n|-|\n|\\\\\\\\\\||", "html": "
1
\\\\|
", - "example": 3 + "example": 6 }, { "section": "Table cells", "markdown": "|1|2|\n|-|-|\n||2|", "html": "
12
2
", - "example": 4 + "example": 7 }, { "section": "Table cells", "markdown": "|1|2|\n|-|-|\n|1\\|\\\\|2\\|\\\\|", "html": "
12
1|\\2|\\
", - "example": 5 + "example": 8 } ] From 898f61294d8cc7c751cc32bda19636492335c056 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 4 Jun 2018 15:23:55 -0500 Subject: [PATCH 6/8] add comments for clarity --- lib/marked.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/marked.js b/lib/marked.js index 9a669655a1..7e9c517e85 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -1340,6 +1340,8 @@ function merge(obj) { } function splitCells(tableRow, count) { + // ensure that every cell-delimiting pipe has a space + // before it to distinguish it from an escaped pipe var row = tableRow.replace(/\|/g, function (match, offset, str) { var escaped = false, curr = offset; @@ -1363,6 +1365,7 @@ function splitCells(tableRow, count) { } for (; i < cells.length; i++) { + // leading or trailing whitespace is ignored per the gfm spec cells[i] = cells[i].trim().replace(/\\\|/g, '|'); } return cells; From 9de68ccba8184ccb2611189e18b07e553438d427 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 11 Jun 2018 08:39:52 -0500 Subject: [PATCH 7/8] add empty cell test --- test/specs/marked/marked.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index e2ff694db1..4e3abb4eb9 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -46,5 +46,11 @@ "markdown": "|1|2|\n|-|-|\n|1\\|\\\\|2\\|\\\\|", "html": "
12
1|\\2|\\
", "example": 8 + }, + { + "section": "Table cells", + "markdown": "|1|2|\n|-|-|\n| |2|", + "html": "
12
2
", + "example": 9 } ] From 9407cef29a9c71f8f04578e44521db7e08dab286 Mon Sep 17 00:00:00 2001 From: Tony Brix Date: Mon, 11 Jun 2018 14:58:30 -0500 Subject: [PATCH 8/8] fix test with a single escaped pipe --- test/specs/marked/marked.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/specs/marked/marked.json b/test/specs/marked/marked.json index 4e3abb4eb9..60c2023827 100644 --- a/test/specs/marked/marked.json +++ b/test/specs/marked/marked.json @@ -13,8 +13,8 @@ }, { "section": "Table cells", - "markdown": "|1|\n|-|\n|1\\||", - "html": "
1
1|
", + "markdown": "|1|\n|-|\n|\\||", + "html": "
1
|
", "example": 3 }, {