tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
379 stars 45 forks source link

add an 'info_string' field under fenced_code_block #43

Closed the-mikedavis closed 2 years ago

the-mikedavis commented 2 years ago

The field is nice because it allows you to use the ! operator in queries. So you could highlight a fenced code-block that doesn't declare a language with a default color when the info_string field doesn't exist:

; highlights.scm
(fenced_code_block
  !info_string
  (code_fence_content) @markup.raw.block)

(fenced_code_block_delimiter) @markup.raw.block

; injections.scm
(fenced_code_block
  info_string: (info_string) @injection.language
  (code_fence_content) @injection.content)

Also included is a bump to tree-sitter-cli 0.20.6. What do you think?

MDeiml commented 2 years ago

I'm welcome to these changes. But if I understand correctly the cli version is not actually specified in the config but rather something I have to update locally, right?

the-mikedavis commented 2 years ago

Currently yeah, it's not specifying in the repo so you need to update locally with however you installed tree-sitter-cli initially.

Most grammars I've seen add tree-sitter-cli as a devDependency and run it through npx tree-sitter, like here in tree-sitter-rust. That way you can pin an exact version.

MDeiml commented 2 years ago

Ah ok, thanks. I'll probably add something like that later than.