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.
This commit is contained in:
Gusted 2024-12-04 21:56:56 +01:00
parent 790f3c4861
commit 216a542bfb
No known key found for this signature in database
GPG key ID: FD821B732837125F
2 changed files with 14 additions and 0 deletions

View file

@ -65,6 +65,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