Implement Text interface for BaseBlock

This implementation was missing, making it impossible to retrieve Text
from block types, such as CodeBlock and FencedCodeBlock, via the ast
interface.
This commit is contained in:
Chris Bednarski 2024-07-25 22:37:54 -07:00
parent 15ade8aace
commit e44645afbb

View file

@ -1,6 +1,7 @@
package ast
import (
"bytes"
"fmt"
"strings"
@ -47,6 +48,14 @@ func (b *BaseBlock) SetLines(v *textm.Segments) {
b.lines = v
}
func (b *BaseBlock) Text(source []byte) []byte {
var buf bytes.Buffer
for _, line := range b.Lines().Sliced(0, b.Lines().Len()) {
buf.Write(line.Value(source))
}
return buf.Bytes()
}
// A Document struct is a root node of Markdown text.
type Document struct {
BaseBlock