8000 fix(gfm-codeblock): add support for spaces before language declaration · showdownjs/showdown@24bf7b1 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 24bf7b1

Browse files
notleetivie
authored andcommitted
fix(gfm-codeblock): add support for spaces before language declaration
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
1 parent c716758 commit 24bf7b1

7 files changed

+18
-5
lines changed

dist/showdown.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.js.map

Expand all lines: dist/showdown.js.map
+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/showdown.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/subParsers/githubCodeBlocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ showdown.subParser('githubCodeBlocks', function (text, options, globals) {
2020

2121
text += '¨0';
2222

23-
text = text.replace(/(?:^|\n)(```+|~~~+)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
23+
text = text.replace(/(?:^|\n)(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
2424
var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
2525

2626
// First parse the github code block

test/cases/github-style-codeblock.html

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
<p>And some HTML</p>
77
<pre><code class="html language-html">&lt;div&gt;HTML!&lt;/div&gt;
88
</code></pre>
9+
<p>And some CSS with spaces before the language declaration</p>
10+
<pre><code class="css language-css">body {
11+
font-size: 1.5em;
12+
}
13+
</code></pre>
914
<p>Use more than 3 backticks</p>
1015
<pre><code>some code
1116
</code></pre>

test/cases/github-style-codeblock.md

+8
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ And some HTML
1313
<div>HTML!</div>
1414
```
1515

16+
And some CSS with spaces before the language declaration
17+
18+
``` css
19+
body {
20+
font-size: 1.5em;
21+
}
22+
```
23+
1624
Use more than 3 backticks
1725

1826
`````

0 commit comments

Comments
 (0)
0