-
Is there any way to check if my document has a specific Heading title? And in case there is how can I extract its section from the document? I appreciate the help. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
What I got so far was this: doc := gm.Parser().Parse(text.NewReader(source))
ast.Walk(doc, func(n ast.Node, entering bool) (ast.WalkStatus, error) {
s := ast.WalkStatus(ast.WalkContinue)
var err error
if n.Kind().String() == "Heading" && string(n.Text(source)) == "Title I'm filtering" {
// Apply any logic here
// gets the title
fmt.Println(string(n.Text(source)))
// get block content
fmt.Println(string(n.NextSibling().Text(source)))
// Stop walking
s = ast.WalkStatus(ast.WalkStop)
}
return s, err
}) Is this the right way to do it? |
Beta Was this translation helpful? Give feedback.
-
Thanks for sharing this! I really wanted a minimal example like this and it is just the ticket. |
Beta Was this translation helpful? Give feedback.
-
@mmiranda hey thanks for the example super helpful. I had another question i was hoping you could help wtih; can you please elaborate the difference between TextBlock, and Paragraph? Similarly Text vs String? I went through the docs but didnt find anything helpful there. Thanks in advance 🙏🏾 |
Beta Was this translation helpful? Give feedback.
What I got so far was this:
Is this the right way to do it?