mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
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:
parent
15ade8aace
commit
e44645afbb
1 changed files with 9 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue