From 67a5941f4d8a8b5d6edae9b61019b22b03dff875 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 12:55:49 +0100 Subject: [PATCH 1/5] require closing fence to be on a new line (fix #1058), while still allowing empty code blocks --- lib/marked.js | 2 +- test/new/gfm_code.html | 5 +++++ test/new/gfm_code.md | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/marked.js b/lib/marked.js index 47da4f52b6..ba460fb2c4 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -91,7 +91,7 @@ block.normal = merge({}, block); */ block.gfm = merge({}, block.normal, { - fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n([\s\S]*?)\n? *\1 *(?:\n+|$)/, + fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n(?:|([\s\S]*?)\n) *\1 *(?:\n+|$)/, paragraph: /^/, heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ }); diff --git a/test/new/gfm_code.html b/test/new/gfm_code.html index 0e8c693196..3e6b946f1a 100644 --- a/test/new/gfm_code.html +++ b/test/new/gfm_code.html @@ -14,3 +14,8 @@ + +

Closing fences must lay on a new line:

+
hello()
+^```
+"this should still be in the code block!"
diff --git a/test/new/gfm_code.md b/test/new/gfm_code.md index 126b8e2c75..79d06b16cd 100644 --- a/test/new/gfm_code.md +++ b/test/new/gfm_code.md @@ -33,3 +33,11 @@ ciao ``` + +Closing fences must lay on a new line: + +``` +hello() +^``` +"this should still be in the code block!" +``` From d0aa0b1a08c2c7b539c9865e7ddef6a4a8f0de1f Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 13:01:36 +0100 Subject: [PATCH 2/5] allow the closing fence to be longer that the opening one (pass cm example 93) --- lib/marked.js | 2 +- test/specs/commonmark/commonmark-spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index ba460fb2c4..01bd9abe2f 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -91,7 +91,7 @@ block.normal = merge({}, block); */ block.gfm = merge({}, block.normal, { - fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n(?:|([\s\S]*?)\n) *\1 *(?:\n+|$)/, + fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n(?:|([\s\S]*?)\n) *\1[~`]* *(?:\n+|$)/, paragraph: /^/, heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ }); diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 7cca2d830b..5f8faa94a4 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -160,7 +160,7 @@ describe('CommonMark 0.28 Fenced code blocks', function() { var section = 'Fenced code blocks'; // var shouldPassButFails = []; - var shouldPassButFails = [93, 95, 96, 97, 106, 108, 112]; + var shouldPassButFails = [95, 96, 97, 106, 108, 112]; var willNotBeAttemptedByCoreTeam = []; From 2f19392e34758a8ae432d688edd8469f02642c86 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 13:59:34 +0100 Subject: [PATCH 3/5] handle fenced code blocks ended by end of file (or parent container) and info string compliant to commonmark --- lib/marked.js | 4 ++-- test/specs/commonmark/commonmark-spec.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 01bd9abe2f..845971e091 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -91,7 +91,7 @@ block.normal = merge({}, block); */ block.gfm = merge({}, block.normal, { - fences: /^ *(`{3,}|~{3,})[ \.]*(\S+)? *\n(?:|([\s\S]*?)\n) *\1[~`]* *(?:\n+|$)/, + fences: /^ *(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: *\1[~`]* *(?:\n+|$)|$)/, paragraph: /^/, heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ }); @@ -231,7 +231,7 @@ Lexer.prototype.token = function(src, top) { src = src.substring(cap[0].length); this.tokens.push({ type: 'code', - lang: cap[2], + lang: cap[2] ? cap[2].trim() : cap[2], text: cap[3] || '' }); continue; diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 5f8faa94a4..96697a8f66 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -160,7 +160,7 @@ describe('CommonMark 0.28 Fenced code blocks', function() { var section = 'Fenced code blocks'; // var shouldPassButFails = []; - var shouldPassButFails = [95, 96, 97, 106, 108, 112]; + var shouldPassButFails = [106, 112]; var willNotBeAttemptedByCoreTeam = []; From 30a73a36e3f775f8b738b323b099a2c112aebd8a Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 14:04:42 +0100 Subject: [PATCH 4/5] fences must be indent up to 3 spaces (pass cm example 106) --- lib/marked.js | 2 +- test/specs/commonmark/commonmark-spec.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 845971e091..9383a0bd84 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -91,7 +91,7 @@ block.normal = merge({}, block); */ block.gfm = merge({}, block.normal, { - fences: /^ *(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: *\1[~`]* *(?:\n+|$)|$)/, + fences: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?:\n+|$)|$)/, paragraph: /^/, heading: /^ *(#{1,6}) +([^\n]+?) *#* *(?:\n+|$)/ }); diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 96697a8f66..eccf42e60c 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -160,7 +160,7 @@ describe('CommonMark 0.28 Fenced code blocks', function() { var section = 'Fenced code blocks'; // var shouldPassButFails = []; - var shouldPassButFails = [106, 112]; + var shouldPassButFails = [112]; var willNotBeAttemptedByCoreTeam = []; From ca52d38899e580050f70aa54973dd944f39d0924 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 14:13:37 +0100 Subject: [PATCH 5/5] use only the first word of the inforstring as the languauge in code blocks (pass cm example 112) --- lib/marked.js | 3 ++- test/specs/commonmark/commonmark-spec.js | 3 +-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/marked.js b/lib/marked.js index 9383a0bd84..3efcdb5a7c 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -920,7 +920,8 @@ function Renderer(options) { this.options = options || marked.defaults; } -Renderer.prototype.code = function(code, lang, escaped) { +Renderer.prototype.code = function(code, infostring, escaped) { + var lang = (infostring || '').match(/\S*/)[0]; if (this.options.highlight) { var out = this.options.highlight(code, lang); if (out != null && out !== code) { diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index eccf42e60c..631cb8fa64 100644 --- a/test/specs/commonmark/commonmark-spec.js +++ b/test/specs/commonmark/commonmark-spec.js @@ -159,8 +159,7 @@ describe('CommonMark 0.28 Indented code blocks', function() { describe('CommonMark 0.28 Fenced code blocks', function() { var section = 'Fenced code blocks'; - // var shouldPassButFails = []; - var shouldPassButFails = [112]; + var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = [];