mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-17 07:57:37 +08:00
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:
parent
9184e91268
commit
594c1e4fa0
@ -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")
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user