Skip to content

Commit

Permalink
GFM: be more clever on parsing fenced codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Sep 10, 2016
1 parent c3e6fae commit 2dc33d5
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/kramdown/parser/gfm.rb
Expand Up @@ -85,8 +85,8 @@ def parse_atx_header_gfm_quirk
true
end

FENCED_CODEBLOCK_START = /^[~`]{3,}/
FENCED_CODEBLOCK_MATCH = /^(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^\1\2*\s*?\n/m
FENCED_CODEBLOCK_START = /^[ ]{0,3}[~`]{3,}/
FENCED_CODEBLOCK_MATCH = /^[ ]{0,3}(([~`]){3,})\s*?((\S+?)(?:\?\S*)?)?\s*?\n(.*?)^[ ]{0,3}\1\2*\s*?\n/m
define_parser(:codeblock_fenced_gfm, FENCED_CODEBLOCK_START, nil, 'parse_codeblock_fenced')

STRIKETHROUGH_DELIM = /~~/
Expand Down
20 changes: 20 additions & 0 deletions test/testcases_gfm/codeblock_fenced.html
@@ -0,0 +1,20 @@
<p>normal</p>

<pre><code class="language-ruby">require 'kramdown'

Kramdown::Document.new(text).to_html
</code></pre>

<p>indent with tab</p>

<pre><code>```ruby
require 'kramdown'

Kramdown::Document.new(text).to_html
```
</code></pre>

<p>indent with 2 spaces</p>

<pre><code class="language-js"> console.log("hello");
</code></pre>
1 change: 1 addition & 0 deletions test/testcases_gfm/codeblock_fenced.options
@@ -0,0 +1 @@
:enable_coderay: false
21 changes: 21 additions & 0 deletions test/testcases_gfm/codeblock_fenced.text
@@ -0,0 +1,21 @@
normal

```ruby
require 'kramdown'

Kramdown::Document.new(text).to_html
```

indent with tab

```ruby
require 'kramdown'

Kramdown::Document.new(text).to_html
```

indent with 2 spaces

```js
console.log("hello");
```

0 comments on commit 2dc33d5

Please sign in to comment.