fix: guard FirstChild() nil in paragraph renderer

A paragraph node with no children causes FirstChild() to return nil,
making both the entering and leaving Kind() checks panic. Cache the
result once and treat nil the same as a non-RawHTML child (emit <p>).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Manuel Rüger 2026-03-13 01:21:11 +01:00
parent 9184e91268
commit 594c1e4fa0

View File

@ -24,8 +24,9 @@ func (r *ConfluenceParagraphRenderer) RegisterFuncs(reg renderer.NodeRendererFun
}
func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
firstChild := n.FirstChild()
if entering {
if n.FirstChild().Kind() != ast.KindRawHTML {
if firstChild == nil || firstChild.Kind() != ast.KindRawHTML {
if n.Attributes() != nil {
_, _ = w.WriteString("<p")
html.RenderAttributes(w, n, html.ParagraphAttributeFilter)
@ -35,7 +36,7 @@ func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source [
}
}
} else {
if n.FirstChild().Kind() != ast.KindRawHTML {
if firstChild == nil || firstChild.Kind() != ast.KindRawHTML {
_, _ = w.WriteString("</p>")
}
_, _ = w.WriteString("\n")