Skip to content

Commit

Permalink
Fix panic on empty blockquotes
Browse files Browse the repository at this point in the history
While renderer previously assumed there would always be a single
paragraph inside the blockquote, there sometimes can be either more or
none.

See #5.
  • Loading branch information
tdemin committed Aug 13, 2021
1 parent e5d7911 commit 845bfa7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions internal/gemini/renderer.go
Expand Up @@ -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)
}
}
}
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 845bfa7

Please sign in to comment.