From 6259f37bd643af647171a286f2a37931c0c1f107 Mon Sep 17 00:00:00 2001 From: Estevao Soares dos Santos Date: Sat, 15 Sep 2018 14:58:50 +0100 Subject: [PATCH] fix(gfm-codeblocks): leading space no longer breaks gfm codeblocks Now GFM Code Blocks can have up to 3 spaces before the backticks Closes #523 --- src/subParsers/makehtml/githubCodeBlocks.js | 2 +- ....leading-space-breaks-gfm-code-blocks.html | 15 ++++++++++++++ ...23.leading-space-breaks-gfm-code-blocks.md | 20 +++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.html create mode 100644 test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.md diff --git a/src/subParsers/makehtml/githubCodeBlocks.js b/src/subParsers/makehtml/githubCodeBlocks.js index 2976b497..f29ec955 100644 --- a/src/subParsers/makehtml/githubCodeBlocks.js +++ b/src/subParsers/makehtml/githubCodeBlocks.js @@ -20,7 +20,7 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals text += 'ยจ0'; - text = text.replace(/(?:^|\n)(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) { + text = text.replace(/(?:^|\n)(?: {0,3})(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n(?: {0,3})\1/g, function (wholeMatch, delim, language, codeblock) { var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n'; // First parse the github code block diff --git a/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.html b/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.html new file mode 100644 index 00000000..ab9ddaa3 --- /dev/null +++ b/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.html @@ -0,0 +1,15 @@ +
var test = test;
+function foo() {
+  return 'bar';
+}
+
+
var test = test;
+function foo() {
+  return 'bar';
+}
+
+
var test = test;
+function foo() {
+  return 'bar';
+}
+
diff --git a/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.md b/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.md new file mode 100644 index 00000000..9289cd06 --- /dev/null +++ b/test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.md @@ -0,0 +1,20 @@ + ```javascript +var test = test; +function foo() { + return 'bar'; +} + ``` + + ```javascript +var test = test; +function foo() { + return 'bar'; +} + ``` + + ```javascript +var test = test; +function foo() { + return 'bar'; +} + ```