0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-12-22 15:23:14 -05:00

Merge pull request 'fix: remove softbreak from github legacy callout' (#6152) from gusted/forgejo-callout into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6152
Reviewed-by: Otto <otto@codeberg.org>
This commit is contained in:
Otto 2024-12-04 23:11:59 +00:00
commit ab00d875b8
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) attentionParagraph.AppendChild(attentionParagraph, calloutNode)
firstParagraph.Parent().InsertBefore(firstParagraph.Parent(), firstParagraph, attentionParagraph) firstParagraph.Parent().InsertBefore(firstParagraph.Parent(), firstParagraph, attentionParagraph)
firstParagraph.RemoveChild(firstParagraph, calloutNode) 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 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(">\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>`)
} }