MeanderingProgrammer / markdown.nvim

Plugin to improve viewing Markdown files in Neovim
MIT License
504 stars 20 forks source link

Highlight only in the markdown injection area for non-markdown file? #3

Closed lkhphuc closed 3 months ago

lkhphuc commented 4 months ago

Hi, I'm the one asking about activating this plugin on other file type on reddit. Thanks for quickly adding the ability. My use case currently is I inject markdown highlight on all the code standalone multi-line string in python. With this the standard markdown highlighting work perfectly.

; after/queries/python/injections.scm
;extends

(module
  (expression_statement
    (string
      (string_content) @injection.content)
    )
  (#set! injection.language "markdown")
  )

With this plugin enabled for python file, the highlighting does work, but I noticed it also highlight the python comments, outside of the """ multiline string that is injected as markdown.

Screenshot 2024-03-22 at 14 48 43

Do you know a way to restrict the highlighting just to this injected markdown reason?

MeanderingProgrammer commented 3 months ago

Hmm, I've not worked with injections in tree-sitter, but I imagine what's happening is your injection correctly only adds the markdown to the relevant section of the buffer. Whereas this plugin attempts to interpret the entire buffer as markdown and finds it in places outside of comments.

I don't have a quick fix in mind, I would need to effectively use the tree of the buffer as it actually exists instead of creating a separate tree here: https://github.com/MeanderingProgrammer/markdown.nvim/blob/main/lua/render-markdown/init.lua#L112. This might be a better approach in general and doesn't seem very difficult so worth trying it out.

MeanderingProgrammer commented 3 months ago

This should be resolved with the following change: https://github.com/MeanderingProgrammer/markdown.nvim/commit/e64255d52dcdf05eb37d9e93fbfd300648c4c4dd.

Please update the plugin and let me know if it behaves as intended.