tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
411 stars 52 forks source link

help: how to query code_span #104

Closed mycf closed 1 year ago

mycf commented 1 year ago

Code not working

vim.treesitter.query.parse("markdown", [[ (paragraph (inline  (code_span)  @codespan)) ]])
MDeiml commented 1 year ago

See also my answer to the other issue you opened https://github.com/MDeiml/tree-sitter-markdown/issues/103#issuecomment-1604258943

I looked a bit into the neovim api. The main problem is that the code_span node is part of the "markdown_inline" grammar, so the following would work for example

vim.treesitter.query.parse("markdown_inline", [[ (code_span)  @codespan ]])

But this obviously wouldn't check if the code_span is inside a paragraph and would also return code spans that are for example in a heading. Not sure if that is a problem?

Also you will have to make sure to call it on the markdown_inline tree and not the markdown tree. Let me know if you need any other help.