Skip to content

Commit

Permalink
fix: don't render divider inside heading
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesKaufmann committed Jan 23, 2022
1 parent cad6dec commit 7a10c54
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions commonmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ var commonmark = []Rule{
{
Filter: []string{"hr"},
Replacement: func(content string, selec *goquery.Selection, opt *Options) *string {
// e.g. `## --- Heading` would look weird, so don't render a divider if inside a heading
insideHeading := selec.ParentsFiltered("h1,h2,h3,h4,h5,h6").Length() > 0
if insideHeading {
return String("")
}

text := "\n\n" + opt.HorizontalRule + "\n\n"
return &text
},
Expand Down
2 changes: 2 additions & 0 deletions testdata/TestCommonmark/heading/goldmark.golden
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@
<h1>not title</h1>
<p>not title
\-\-\-</p>
<h4>More posts from around the site:</h4>
<h4>More posts from around the site:</h4>
10 changes: 9 additions & 1 deletion testdata/TestCommonmark/heading/input.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,12 @@ <h1>#hashtag</h1>
<p>
not title
\-\-\-
</p>
</p>


<!--heading with divider-->
<h4><hr>More posts from around the site:</h4>
<h4><span>
<hr>
More posts from around the site:
<span></h4>
6 changes: 5 additions & 1 deletion testdata/TestCommonmark/heading/output.atx.golden
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ not title
=

not title
\\-\\-\\-
\\-\\-\\-

#### More posts from around the site:

#### More posts from around the site:
6 changes: 5 additions & 1 deletion testdata/TestCommonmark/heading/output.setext.golden
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ not title
=

not title
\\-\\-\\-
\\-\\-\\-

#### More posts from around the site:

#### More posts from around the site:

0 comments on commit 7a10c54

Please sign in to comment.