diff --git a/lib/marked.js b/lib/marked.js index 47da4f52b6..3efcdb5a7c 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: /^ {0,3}(`{3,}|~{3,})([^`\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\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; @@ -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/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!" +``` diff --git a/test/specs/commonmark/commonmark-spec.js b/test/specs/commonmark/commonmark-spec.js index 7cca2d830b..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 = [93, 95, 96, 97, 106, 108, 112]; + var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = [];