I'm making a little script using treesitter that will extract all code blocks inside an ORG file, but only if they're under an headline with a specific property (:TANGLE:).
I was able to make this query, which works, but only finds code blocks that are immediate children of the headline:
(section
(property_drawer
(property
name: (expr) @prop_name (#eq? @prop_name "TANGLE")
value: (value) @file
)
)
(body
(block
contents: (contents) @code
)
)
)
It works with this org file:
* Headline
:PROPERTIES:
:TANGLE: file.lua
:END:
#+begin_src lua
print("test")
#+end_src
But not with this one, because the code block is not directly inside "Headline 1":
* Headline 1
:PROPERTIES:
:TANGLE: file.lua
:END:
** Headline 2
#+begin_src lua
print("test")
#+end_src
Is there a way using treesitter queries to get nodes nested at any depth inside the headline?