Skip to content

Commit

Permalink
fix: Code and heading after list without blank line (#2483)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiyoka authored Jun 13, 2022
1 parent 4844bc1 commit 15f3f15
Show file tree
Hide file tree
Showing 9 changed files with 127 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Tokenizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export class Tokenizer {
if (!endEarly) {
const nextBulletRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}(?:[*+-]|\\d{1,9}[.)])((?: [^\\n]*)?(?:\\n|$))`);
const hrRegex = new RegExp(`^ {0,${Math.min(3, indent - 1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`);
const fencesBeginRegex = new RegExp(`^( {0,${Math.min(3, indent - 1)}})(\`\`\`|~~~)`);

// Check if following lines should be included in List Item
while (src) {
Expand All @@ -237,6 +238,16 @@ export class Tokenizer {
line = line.replace(/^ {1,4}(?=( {4})*[^ ])/g, ' ');
}

// End list item if found code fences
if (fencesBeginRegex.test(line)) {
break;
}

// End list item if found start of new heading
if (this.rules.block.heading.test(line)) {
break;
}

// End list item if found start of new bullet
if (nextBulletRegex.test(line)) {
break;
Expand Down
7 changes: 7 additions & 0 deletions test/specs/new/fences_following_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<ol>
<li>abcd</li>
</ol>
<pre><code>if {

}
</code></pre>
5 changes: 5 additions & 0 deletions test/specs/new/fences_following_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
1. abcd
```
if {
}
```
23 changes: 23 additions & 0 deletions test/specs/new/fences_with_blankline_following_list_0.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<ol>
<li>code with blankline</li>
</ol>
<pre><code>if {

}
</code></pre>
<ol start="2">
<li>code and text</li>
</ol>
<pre><code>if {

}
</code></pre>
<p>text after fenced code block.</p>
<ol start="3">
<li>tilde</li>
</ol>
<pre><code>if {


}
</code></pre>
22 changes: 22 additions & 0 deletions test/specs/new/fences_with_blankline_following_list_0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. code with blankline
```
if {
}
```

2. code and text
```
if {
}
```
text after fenced code block.

3. tilde
~~~
if {
}
~~~
22 changes: 22 additions & 0 deletions test/specs/new/fences_with_blankline_following_list_1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<ol>
<li><p>code with blankline</p>
<pre><code>if {

}
</code></pre>
</li>
<li><p>code and text</p>
<pre><code>if {

}
</code></pre>
<p>text after fenced code block.</p>
</li>
<li><p>tilde</p>
<pre><code>if {


}
</code></pre>
</li>
</ol>
23 changes: 23 additions & 0 deletions test/specs/new/fences_with_blankline_following_list_1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
1. code with blankline
```
if {
}
```

2. code and text
```
if {
}
```
text after fenced code block.

3. tilde
~~~
if {
}
~~~

8 changes: 8 additions & 0 deletions test/specs/new/heading_following_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<h1 id="level1">level1</h1>
<h2 id="level2">level2</h2>
<h3 id="level3">level3</h3>
<ul>
<li>foo=bar</li>
<li>foo2=bar2</li>
</ul>
<h3 id="level3-1">level3</h3>
6 changes: 6 additions & 0 deletions test/specs/new/heading_following_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# level1
## level2
### level3
- foo=bar
- foo2=bar2
### level3

1 comment on commit 15f3f15

@vercel
Copy link

@vercel vercel bot commented on 15f3f15 Jun 13, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.