mirror of
https://github.com/kovetskiy/mark.git
synced 2026-03-19 17:17:38 +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) {
|
func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source []byte, n ast.Node, entering bool) (ast.WalkStatus, error) {
|
||||||
|
firstChild := n.FirstChild()
|
||||||
if entering {
|
if entering {
|
||||||
if n.FirstChild().Kind() != ast.KindRawHTML {
|
if firstChild == nil || firstChild.Kind() != ast.KindRawHTML {
|
||||||
if n.Attributes() != nil {
|
if n.Attributes() != nil {
|
||||||
_, _ = w.WriteString("<p")
|
_, _ = w.WriteString("<p")
|
||||||
html.RenderAttributes(w, n, html.ParagraphAttributeFilter)
|
html.RenderAttributes(w, n, html.ParagraphAttributeFilter)
|
||||||
@ -35,7 +36,7 @@ func (r *ConfluenceParagraphRenderer) renderParagraph(w util.BufWriter, source [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if n.FirstChild().Kind() != ast.KindRawHTML {
|
if firstChild == nil || firstChild.Kind() != ast.KindRawHTML {
|
||||||
_, _ = w.WriteString("</p>")
|
_, _ = w.WriteString("</p>")
|
||||||
}
|
}
|
||||||
_, _ = w.WriteString("\n")
|
_, _ = w.WriteString("\n")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user