From e44645afbb6814bb93536587a5d4af43ad3ab2ef Mon Sep 17 00:00:00 2001 From: Chris Bednarski Date: Thu, 25 Jul 2024 22:37:54 -0700 Subject: [PATCH] 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. --- ast/block.go | 9 +++++++++ 1 file changed, 9 insertions(+) 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