From e741d0a068411dece5c8e6cf269aaa46baf4b538 Mon Sep 17 00:00:00 2001 From: Gusted Date: Wed, 4 Dec 2024 21:56:56 +0100 Subject: [PATCH] fix: remove softbreak from github legacy callout - A softbreak was being preserved during the github legacy callout (this is likely due to a change in Goldmark) while it should not. This caused an `
` to be present between the attention title and attention content. - Added unit test. (cherry picked from commit 216a542bfbd4534b304f9ca6d4d8e6a36f9a8ca1) --- modules/markup/markdown/callout/github_legacy.go | 8 ++++++++ modules/markup/markdown/markdown_test.go | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/modules/markup/markdown/callout/github_legacy.go b/modules/markup/markdown/callout/github_legacy.go index 32a278bc8d..96354b142b 100644 --- a/modules/markup/markdown/callout/github_legacy.go +++ b/modules/markup/markdown/callout/github_legacy.go @@ -63,6 +63,14 @@ func (g *GitHubLegacyCalloutTransformer) Transform(node *ast.Document, reader te attentionParagraph.AppendChild(attentionParagraph, calloutNode) firstParagraph.Parent().InsertBefore(firstParagraph.Parent(), firstParagraph, attentionParagraph) firstParagraph.RemoveChild(firstParagraph, calloutNode) + + // Remove softbreak line if there's one. + if firstParagraph.ChildCount() >= 1 { + softBreakNode, ok := firstParagraph.FirstChild().(*ast.Text) + if ok && softBreakNode.SoftLineBreak() { + firstParagraph.RemoveChild(firstParagraph, softBreakNode) + } + } } return ast.WalkContinue, nil diff --git a/modules/markup/markdown/markdown_test.go b/modules/markup/markdown/markdown_test.go index e3dc6c9655..cc2becad05 100644 --- a/modules/markup/markdown/markdown_test.go +++ b/modules/markup/markdown/markdown_test.go @@ -1356,4 +1356,10 @@ func TestCallout(t *testing.T) { } test(">\n0", "
\n
\n

0

") + test("> **Warning**\n> Bad stuff is brewing here", `

Warning

+

Bad stuff is brewing here

+
`) + test("> [!WARNING]\n> Bad stuff is brewing here", `

Warning

+

Bad stuff is brewing here

+
`) }