1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-21 12:44:49 -05:00

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 `<br>` to be present between the attention title and attention content.
- Added unit test.

(cherry picked from commit 216a542bfb)
This commit is contained in:
Gusted 2024-12-04 21:56:56 +01:00 committed by forgejo-backport-action
parent ad1aad7b1a
commit e741d0a068
2 changed files with 14 additions and 0 deletions

View file

@ -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

View file

@ -1356,4 +1356,10 @@ func TestCallout(t *testing.T) {
}
test(">\n0", "<blockquote>\n</blockquote>\n<p>0</p>")
test("> **Warning**\n> Bad stuff is brewing here", `<blockquote class="attention-header attention-warning"><p class="attention-title"><strong class="attention-warning">Warning</strong></p>
<p>Bad stuff is brewing here</p>
</blockquote>`)
test("> [!WARNING]\n> Bad stuff is brewing here", `<blockquote class="attention-header attention-warning"><p class="attention-title"><strong class="attention-warning">Warning</strong></p>
<p>Bad stuff is brewing here</p>
</blockquote>`)
}