瀏覽代碼

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

部分文件因文件數量過多而無法顯示