Hello, goldmark is great and I've been enjoying using it for several projects now. Thanks for working on this!
I've run into a snag with the ast where I can't read node.Text() for code blocks. Headings work OK, and I can see the data using Dump() and Lines() has the right offsets.
Here's my repro case. Thanks!
main.go
package main
import (
"fmt"
"github.com/yuin/goldmark"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/text"
)
var data = []byte(`# A heading
some code in a code block
`)
func main() {
rootNode := goldmark.New().Parser().Parse(text.NewReader(data))
if err := ast.Walk(rootNode, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
if entering {
return ast.WalkContinue, nil
}
switch n.Kind() {
case ast.KindHeading:
fmt.Println("heading:", string(n.Text(data)))
case ast.KindCodeBlock:
fmt.Println("codeblock:", string(n.Text(data)))
for _, line := range n.Lines().Sliced(0, n.Lines().Len()) {
fmt.Println(line.Value(data))
}
pos := n.Lines().At(0)
fmt.Println("start:", pos.Start,
"stop:", pos.Stop,
"data:", string(data[pos.Start:pos.Stop]))
}
return ast.WalkContinue, nil
}); err != nil {
panic(err)
}
}
Output:
$ go run .
heading: A heading
codeblock: <-------------- missing data!
start: 14 stop: 39 data: some code in a code block
Please answer the following before submitting your issue:
What version of goldmark are you using? : github.com/yuin/goldmark v1.7.4
What version of Go are you using? : go version go1.23rc2
What operating system and processor architecture are you using? : linux/amd64
Hello, goldmark is great and I've been enjoying using it for several projects now. Thanks for working on this!
I've run into a snag with the ast where I can't read
node.Text()
for code blocks. Headings work OK, and I can see the data usingDump()
andLines()
has the right offsets.Here's my repro case. Thanks!
main.go
Output:
Please answer the following before submitting your issue:
github.com/yuin/goldmark v1.7.4
go version go1.23rc2
linux/amd64