소스 검색

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
Lee Moody 7 년 전
부모
커밋
1f0242c6ea

파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 4 - 4
dist/showdown.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/showdown.js.map


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 1
dist/showdown.min.js


파일 크기가 너무 크기때문에 변경 상태를 표시하지 않습니다.
+ 0 - 0
dist/showdown.min.js.map


+ 1 - 1
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)(```+|~~~+)(?: *)([^\s`~]*)\n([\s\S]*?)\n\1/g, function (wholeMatch, delim, language, codeblock) {
     var end = (options.omitExtraWLInCodeBlocks) ? '' : '\n';
 
     // First parse the github code block

+ 5 - 0
test/functional/makehtml/cases/standard/github-style-codeblock.html

@@ -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>

+ 8 - 0
test/functional/makehtml/cases/standard/github-style-codeblock.md

@@ -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
 
 `````

이 변경점에서 너무 많은 파일들이 변경되어 몇몇 파일들은 표시되지 않았습니다.