Skip to content

Commit

Permalink
fix: fix hr after list (#2809)
Browse files Browse the repository at this point in the history
  • Loading branch information
azmy60 committed May 30, 2023
1 parent 26b42ec commit efc40df
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/rules.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const block = {
+ ')',
def: /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
table: noopTest,
lheading: /^((?:.|\n(?!\n))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
lheading: /^((?:(?!^bull ).|\n(?!\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
// regex template, placeholders will be replaced according to different paragraph
// interruption rules of commonmark and the original markdown spec:
_paragraph: /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
Expand Down Expand Up @@ -64,6 +64,10 @@ block.html = edit(block.html, 'i')
.replace('attribute', / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
.getRegex();

block.lheading = edit(block.lheading)
.replace(/bull/g, block.bullet) // lists can interrupt
.getRegex();

block.paragraph = edit(block._paragraph)
.replace('hr', block.hr)
.replace('heading', ' {0,3}#{1,6} ')
Expand Down
36 changes: 36 additions & 0 deletions test/specs/new/incorrectly_formatted_list_and_hr.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<ul>
<li>this is a list, not a heading</li>
</ul>
<hr />

<ol>
<li>this is also a list</li>
</ol>
<ul>
<li>it should be a list</li>
</ul>
<ul>
<li>not heading</li>
</ul>
<hr />

<p><s>not heading</s></p>
<ul>
<li>this is also a list, not a multiline heading</li>
</ul>
<hr />

<p><a href="/index.jpg">click here</a></p>
<ul>
<li>this has to be a list</li>
<li>true...</li>
</ul>
<hr />

<h2 id="heading--this-one-is-a-heading">
<b>heading</b> -this one is a heading
</h2>

<h2 id="heading---this-is-a-heading-too">
<b>heading</b> - this is a heading too
</h2>
23 changes: 23 additions & 0 deletions test/specs/new/incorrectly_formatted_list_and_hr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
- this is a list, not a heading
-----

1) this is also a list
* it should be a list
- not heading
-----

<s>not heading</s>
- this is also a list, not a multiline heading
*****

[click here](/index.jpg)
- this has to be a list
- true...
_____

<b>heading</b>
-this one is a heading
-----

<b>heading</b> - this is a heading too
-----

1 comment on commit efc40df

@vercel
Copy link

@vercel vercel bot commented on efc40df May 30, 2023

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.