Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions queries/injections.scm
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@
((expression (expression_value) @injection.content)
(#set! injection.language "elixir")
(#set! injection.include-children))

; Sintax highlight for style and javascript tags
((tag
(start_tag
(tag_name) @tag_name (#eq? @tag_name "script"))
(text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can capture the (text) node here as (text) @injection.content instead and then you can drop the #offset! property below

(and same for the style tag below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that but it stops the capture right before the next { character inside the script tag

((tag
  (start_tag
      (tag_name) @tag_name (#eq? @tag_name "script"))
  (text) @injection.content
  (end_tag)
) 
 (#set! injection.language "javascript")
 (#set! injection.include-children)
 (#set! injection.combined)
)
image

and results something like this when you have several functions:

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah I see, we need to parse the entire inner contents of the tag because otherwise {/} are recognized as non-(text) nodes 👍

(end_tag)
) @injection.content
(#offset! @injection.content 1 0 0 -9)
(#set! injection.language "javascript")
(#set! injection.include-children)
(#set! injection.combined)
)

((tag
(start_tag
(tag_name) @tag_name (#eq? @tag_name "style"))
(text)
(end_tag)
) @injection.content
(#offset! @injection.content 1 0 0 -9)
(#set! injection.language "css")
(#set! injection.include-children)
(#set! injection.combined)
)