2020-06-19 01:00:24 +00:00
|
|
|
package segments
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/diamondburned/cchat/text"
|
|
|
|
"github.com/yuin/goldmark/ast"
|
|
|
|
)
|
|
|
|
|
|
|
|
type BlockquoteSegment struct {
|
|
|
|
start, end int
|
|
|
|
}
|
|
|
|
|
|
|
|
var _ text.Quoteblocker = (*BlockquoteSegment)(nil)
|
|
|
|
|
|
|
|
func (r *TextRenderer) blockquote(n *ast.Blockquote, enter bool) ast.WalkStatus {
|
|
|
|
if enter {
|
2020-07-08 21:23:14 +00:00
|
|
|
// Block formatting.
|
|
|
|
r.ensureBreak()
|
|
|
|
defer r.ensureBreak()
|
2020-06-19 01:53:09 +00:00
|
|
|
|
2020-06-19 01:00:24 +00:00
|
|
|
// Create a segment.
|
2020-07-08 08:35:30 +00:00
|
|
|
var seg = BlockquoteSegment{start: r.buf.Len()}
|
2020-06-19 01:00:24 +00:00
|
|
|
|
|
|
|
// A blockquote contains a paragraph each line. Because Discord.
|
|
|
|
for child := n.FirstChild(); child != nil; child = child.NextSibling() {
|
|
|
|
r.buf.WriteString("> ")
|
|
|
|
|
|
|
|
ast.Walk(child, func(node ast.Node, enter bool) (ast.WalkStatus, error) {
|
|
|
|
// We only call when entering, since we don't want to trigger a
|
|
|
|
// hard new line after each paragraph.
|
|
|
|
if enter {
|
|
|
|
return r.renderNode(node, enter)
|
|
|
|
}
|
|
|
|
return ast.WalkContinue, nil
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the end of the segment.
|
2020-07-08 08:35:30 +00:00
|
|
|
seg.end = r.buf.Len()
|
2020-06-19 01:00:24 +00:00
|
|
|
r.append(seg)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ast.WalkSkipChildren
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BlockquoteSegment) Bounds() (start, end int) {
|
|
|
|
return b.start, b.end
|
|
|
|
}
|
|
|
|
|
|
|
|
func (b BlockquoteSegment) Quote() {}
|