From d3baaaa412e5aa425d72662ba6f435b0efafc770 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 d06cffa7acf1592f22e5683b3cff19e7f978cd7c 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 574b665b763667aa02dd80f854696632a3db0975 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 fe5f259ce02ce56c198887544012ec0aaa4eadea 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 66f39e05bac475238aeebd544d990ef17bbeeba0 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 1879717cbaf76302284edaf35fa99c3c714e678a 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 e3af8d936735f03d443cb270313bc2996bae289d 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 877eecd1279d6f7b6b6e66d8dfabaa25f80cfe81 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 }, {