Skip to content

Commit

Permalink
fix(gfm-codeblock): add support for spaces before language declaration
Browse files Browse the repository at this point in the history
One or more spaces before the language declaration of a code block is supported by Github.

E.g.

```    html
<div>HTML!</div>
```

``` html
<div>HTML!</div>
```

```html
<div>HTML!</div>
```

Closes #569
  • Loading branch information
notlee authored and tivie committed Oct 16, 2018
1 parent c716758 commit 24bf7b1
Show file tree
Hide file tree
Showing 7 changed files with 18 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)(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';

// First parse the github code block
Expand Down
5 changes: 5 additions & 0 deletions test/cases/github-style-codeblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
<p>And some HTML</p>
<pre><code class="html language-html">&lt;div&gt;HTML!&lt;/div&gt;
</code></pre>
<p>And some CSS with spaces before the language declaration</p>
<pre><code class="css language-css">body {
font-size: 1.5em;
}
</code></pre>
<p>Use more than 3 backticks</p>
<pre><code>some code
</code></pre>
Expand Down
8 changes: 8 additions & 0 deletions test/cases/github-style-codeblock.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ And some HTML
<div>HTML!</div>
```

And some CSS with spaces before the language declaration

``` css
body {
font-size: 1.5em;
}
```

Use more than 3 backticks

`````
Expand Down

0 comments on commit 24bf7b1

Please sign in to comment.