From e32342ecc4becf9c2ce2efefca38c7ab0267ead3 Mon Sep 17 00:00:00 2001 From: Federico Soave Date: Sat, 8 Dec 2018 12:55:49 +0100 Subject: [PATCH] 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!" +```