diff --git a/ast/block.go b/ast/block.go index c5d4738..e781a45 100644 --- a/ast/block.go +++ b/ast/block.go @@ -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