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'; +} + ```