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

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>`)
}