Skip to content
Discussion options

You must be logged in to vote

Tree-sitter has injections that are built for this case. This works decently well on simple data contents like the one you list:

; runtime/queries/svelte/injections.scm

((element
  (start_tag (tag_name) @_tag_name)
  (text) @injection.content)
 (#match? @_tag_name "data")
 (#set! injection.language "javascript"))

This is how grammars like svelte and vue highlight javascript to begin with: they don't have a full javascript grammar built-in. Instead they hand off javascript blocks to the javascript parser using injections.

However it doesn't work like how you describe: there's no way to tell tree-sitter to stop parsing for a certain block. It parses using the language for the file as the f…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@aral
Comment options

@aral
Comment options

@arkaragian
Comment options

Answer selected by sudormrfbin
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants