Skip to content

How do highlight links in HTML using treesitter queries? #11392

Answered by the-mikedavis
David-Else asked this question in Q&A
Discussion options

You must be logged in to vote

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.

(tag_name) @tag
(erroneous_end_tag_name) @tag.error
(doctype) @constant
(attribute_name) @attribute
(comment) @comment

((attribute
  (attribute_name) @attribute
  (quoted_attribute_value (attribute_value) @markup.link.url))
 (#any-of? @attribute "href" "src"))

[
  "\""
  (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)
  …

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
2 replies
@the-mikedavis
Comment options

Answer selected by David-Else
@David-Else
Comment options

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