Skip to content

Commit

Permalink
markdown: really fix soft line break rendering (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon authored Mar 28, 2023
1 parent f439075 commit a1bbaa9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
6 changes: 4 additions & 2 deletions markdown/extender.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,12 @@ func (r *nodeRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
}

n := node.(*ast.Text)
if n.SoftLineBreak() {
defer func() { _ = w.WriteByte('\n') }()
}

text := n.Text(source)
if len(text) == 0 {
// Simply write a line break if there is no text in the node, otherwise, soft break lines are sticking.
_ = w.WriteByte('\n')
return ast.WalkContinue, nil
}

Expand Down
3 changes: 1 addition & 2 deletions markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ func TestRenderer(t *testing.T) {
if err != nil {
t.Fatal(err)
}
want := `<h1 id="b"><a name="b" class="anchor" href="#b" rel="nofollow" aria-hidden="true" title="#b"></a>a
</h1>
want := `<h1 id="b"><a name="b" class="anchor" href="#b" rel="nofollow" aria-hidden="true" title="#b"></a>a</h1>
`
if string(doc.HTML) != want {
t.Errorf("got %q, want %q", string(doc.HTML), want)
Expand Down

0 comments on commit a1bbaa9

Please sign in to comment.