Make blockquote read stuff not byte-by-byte

This commit is contained in:
Timur Demin 2020-11-07 19:27:55 +05:00
parent 4799b2b511
commit 3d9314f0a4
No known key found for this signature in database
GPG key ID: 9EDF3F9D9286FA20

View file

@ -3,17 +3,18 @@
package gemini
import (
"bufio"
"bytes"
"io"
"github.com/gomarkdown/markdown/ast"
)
var (
lineBreak = []byte{'\n'}
lineBreakByte byte = 0x0a
space = []byte{' '}
linkPrefix = []byte("=> ")
quotePrefix = []byte("> ")
lineBreak = []byte{'\n'}
space = []byte{' '}
linkPrefix = []byte("=> ")
quotePrefix = []byte("> ")
)
// Renderer implements markdown.Renderer.
@ -75,23 +76,18 @@ 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 {
w.Write(quotePrefix)
if para, ok := node.Children[0].(*ast.Paragraph); ok {
for _, subnode := range para.Children {
if l := subnode.AsLeaf(); l != nil {
// TODO: Renderer.blockquote: rendering by byte is asking
// for optimizations
for _, b := range l.Literal {
w.Write([]byte{b})
if b == lineBreakByte {
w.Write(quotePrefix)
}
reader := bufio.NewScanner(bytes.NewBuffer(l.Literal))
for reader.Scan() {
w.Write(quotePrefix)
w.Write(reader.Bytes())
w.Write(lineBreak)
}
}
}
}
} else {
w.Write(lineBreak)
}
}