How do highlight links in HTML using treesitter queries? #11392
-
I am trying to update the HTML treesitter highlights but have become stuck. I want to highlight just the links inside https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/html_tags/highlights.scm
but this is not working in Helix and causes the highlighting to crash. In the Helix svelte highlights we have:
but that does nothing in HTML. I am stuck, I have tried to see if it works on different themes in case mine has problems. but I am not seeing anything change for |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm not sure what the ((attribute
(attribute_name) @attribute
(quoted_attribute_value (attribute_value) @markup.link.url))
(#any-of? @attribute "href" "src")) (when those queries were written for svelte we didn't support |
Beta Was this translation helpful? Give feedback.
-
@the-mikedavis thanks for the quick reply! Afraid I can't make what you suggested work, what theme are you using? Here is my work so far including your suggestion: (tag_name) @tag
(erroneous_end_tag_name) @tag.error
(doctype) @constant
(attribute_name) @attribute
(comment) @comment
[
"\""
(attribute_value)
] @string
((element
(start_tag
(tag_name) @_tag)
(text) @markup.bold)
(#any-of? @_tag "strong" "b"))
((element
(start_tag
(tag_name) @_tag)
(text) @markup.italic)
(#any-of? @_tag "em" "i"))
((element
(start_tag
(tag_name) @_tag)
(text) @markup.strikethrough)
(#any-of? @_tag "s" "del"))
((attribute
(attribute_name) @attribute
(quoted_attribute_value (attribute_value) @markup.link.url))
(#any-of? @attribute "href" "src"))
[
"<"
">"
"</"
"/>"
"<!"
] @punctuation.bracket
"=" @punctuation.delimiter |
Beta Was this translation helpful? Give feedback.
I think there's a precedence issue: the
(attribute_value)
on L9 (which tags it as@string
) ends up taking precedence over the later pattern. If you reorganize that to be higher I see it highlighting with the link style.