Skip to content

Commit a1bbaa9

Browse files
authored
markdown: really fix soft line break rendering (#95)
1 parent f439075 commit a1bbaa9

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

markdown/extender.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ func (r *nodeRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer) {
173173
}
174174

175175
n := node.(*ast.Text)
176+
if n.SoftLineBreak() {
177+
defer func() { _ = w.WriteByte('\n') }()
178+
}
179+
176180
text := n.Text(source)
177181
if len(text) == 0 {
178-
// Simply write a line break if there is no text in the node, otherwise, soft break lines are sticking.
179-
_ = w.WriteByte('\n')
180182
return ast.WalkContinue, nil
181183
}
182184

markdown/markdown_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,7 @@ func TestRenderer(t *testing.T) {
134134
if err != nil {
135135
t.Fatal(err)
136136
}
137-
want := `<h1 id="b"><a name="b" class="anchor" href="#b" rel="nofollow" aria-hidden="true" title="#b"></a>a
138-
</h1>
137+
want := `<h1 id="b"><a name="b" class="anchor" href="#b" rel="nofollow" aria-hidden="true" title="#b"></a>a</h1>
139138
`
140139
if string(doc.HTML) != want {
141140
t.Errorf("got %q, want %q", string(doc.HTML), want)

0 commit comments

Comments
 (0)