Fix panic on empty blockquotes
While renderer previously assumed there would always be a single paragraph inside the blockquote, there sometimes can be either more or none. See #5.
This commit is contained in:
parent
e5d791165d
commit
845bfa7cb2
1 changed files with 12 additions and 4 deletions
|
@ -86,9 +86,17 @@ func (r Renderer) blockquote(w io.Writer, node *ast.BlockQuote, entering bool) {
|
|||
// TODO: Renderer.blockquote: needs support for subnode rendering;
|
||||
// ideally to be merged with paragraph
|
||||
if entering {
|
||||
if para, ok := node.Children[0].(*ast.Paragraph); ok {
|
||||
w.Write(quotePrefix)
|
||||
r.text(w, para)
|
||||
if node := node.AsContainer(); node != nil {
|
||||
for _, child := range node.Children {
|
||||
w.Write(quotePrefix)
|
||||
// assume children would be paragraphs
|
||||
r.text(w, child)
|
||||
// double linebreak to ensure Gemini clients don't merge
|
||||
// quotes; gomarkdown assumes separate blockquotes are
|
||||
// paragraphs of the same blockquote while we don't
|
||||
w.Write(lineBreak)
|
||||
w.Write(lineBreak)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -137,6 +145,7 @@ func (r Renderer) paragraph(w io.Writer, node *ast.Paragraph, entering bool) (no
|
|||
}
|
||||
linksOnly := func() bool {
|
||||
for _, child := range children {
|
||||
// TODO: simplify
|
||||
if _, ok := child.(*ast.Link); ok {
|
||||
continue
|
||||
}
|
||||
|
@ -329,7 +338,6 @@ func (r Renderer) RenderNode(w io.Writer, node ast.Node, entering bool) ast.Walk
|
|||
switch node := node.(type) {
|
||||
case *ast.BlockQuote:
|
||||
r.blockquote(w, node, entering)
|
||||
noNewLine = false
|
||||
case *ast.Heading:
|
||||
r.heading(w, node, entering)
|
||||
noNewLine = false
|
||||
|
|
Loading…
Reference in a new issue