Skip to content

Commit

Permalink
Make blockquote read stuff not byte-by-byte
Browse files Browse the repository at this point in the history
  • Loading branch information
tdemin committed Nov 7, 2020
1 parent 4799b2b commit 3d9314f
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions internal/gemini/renderer.go
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 3d9314f

Please sign in to comment.