Skip to content

Commit

Permalink
fix(gfm-codeblocks): leading space no longer breaks gfm codeblocks
Browse files Browse the repository at this point in the history
Now GFM Code Blocks can have up to 3 spaces before the backticks

Closes #523
  • Loading branch information
tivie committed Oct 16, 2018
1 parent dfeb1e2 commit 828c32f
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion dist/showdown.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/showdown.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/showdown.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/subParsers/githubCodeBlocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ showdown.subParser('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
Expand Down
15 changes: 15 additions & 0 deletions test/issues/#523.leading-space-breaks-gfm-code-blocks.html
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions test/issues/#523.leading-space-breaks-gfm-code-blocks.md
Original file line number Diff line number Diff line change
@@ -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';
}
```

0 comments on commit 828c32f

Please sign in to comment.