Browse Source

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
Estevao Soares dos Santos 6 years ago
parent
commit
6259f37bd6

+ 1 - 1
src/subParsers/makehtml/githubCodeBlocks.js

@@ -20,7 +20,7 @@ showdown.subParser('makehtml.githubCodeBlocks', function (text, options, globals
 
 
   text += '¨0';
   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';
     var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
 
 
     // First parse the github code block
     // First parse the github code block

+ 15 - 0
test/functional/makehtml/cases/issues/#523.leading-space-breaks-gfm-code-blocks.html

@@ -0,0 +1,15 @@
+<pre><code class="javascript language-javascript">var test = test;
+function foo() {
+  return 'bar';
+}
+</code></pre>
+<pre><code class="javascript language-javascript">var test = test;
+function foo() {
+  return 'bar';
+}
+</code></pre>
+<pre><code class="javascript language-javascript">var test = test;
+function foo() {
+  return 'bar';
+}
+</code></pre>

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