From 72c3f8a0933ce6724b6cf7dfc467ed72bce864d1 Mon Sep 17 00:00:00 2001 From: Joe Chen Date: Tue, 28 Mar 2023 17:11:25 +0800 Subject: [PATCH] markdown: really fix soft line break rendering --- markdown/extender.go | 6 ++++-- markdown/markdown_test.go | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/markdown/extender.go b/markdown/extender.go index 395e116..6fb9bdf 100644 --- a/markdown/extender.go +++ b/markdown/extender.go @@ -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 } diff --git a/markdown/markdown_test.go b/markdown/markdown_test.go index 96f1dac..4a75dfd 100644 --- a/markdown/markdown_test.go +++ b/markdown/markdown_test.go @@ -134,8 +134,7 @@ func TestRenderer(t *testing.T) { if err != nil { t.Fatal(err) } - want := `

a -

+ want := `

a

` if string(doc.HTML) != want { t.Errorf("got %q, want %q", string(doc.HTML), want)