tree-sitter-grammars / tree-sitter-markdown

Markdown grammar for tree-sitter
MIT License
411 stars 52 forks source link

Ignore whitespace in list markers? #79

Closed mushfiq814 closed 1 year ago

mushfiq814 commented 1 year ago

I am trying to write custom highlight queries to target list markers such as list_marker_star. However, the whitespace that is part of this node (*) is also being targeted. I wanted to know if it is possible to query for just the [*-+] character in the list marker nodes using this parser.

Details

I am using treesitter in neovim and am trying to use conceal to replace the list markers with something else. Currently using the following query, the [*-+] (including the whitespace following the list marker) is replaced with my conceal character (using X here for simplicity and for compatibilty with regular fonts) since neovim/vim doesn't support multi character replacements with conceal.

;; extends
([
  (list_marker_star)
  (list_marker_plus)
  (list_marker_minus)
] @conceal
(#set! conceal "X"))

The above query will result in * item 1 becoming Xitem 1 whereas I want it to be X item 1

One workaround I have found is to have characters that the terminal emulator automatically assuems to be double width and renders as such but it is not ideal. Is it possible to just replace the marker and ignore the whitespace?

Please let me know if this isn't the right place to ask this question. I have been trying to achieve this for quite a while with no luck. Thank you for this parser!

MDeiml commented 1 year ago

The [*-+] is not it's own node, so this is not trivial. I assume you are using neovim? Then you could write a directive for your queries, that shrinks the capture to the symbol, see https://neovim.io/doc/user/treesitter.html#treesitter-directives

mushfiq814 commented 1 year ago

Thanks for the response. I can take a look at custom directives.