Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lkhphuc opened this issue Mar 22, 2024 · 2 comments
Closed
Labels
enhancement New feature or request

Comments

@lkhphuc
Copy link
Contributor

lkhphuc commented Mar 22, 2024

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
Copy link
Owner

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 MeanderingProgrammer added the enhancement New feature or request label Mar 22, 2024
MeanderingProgrammer added a commit that referenced this issue Mar 23, 2024
…ng buffer as markdown

## Details

This should solve issue: #3

This will allow for markdown to be rendered with this plugin when
injected in other languages, for example Python comments.

Currently we attempt to parse the entire buffer as markdown which
leads to some strange behavior, i.e. interpretting single line
comments as markdown.

After this change we will read the injected markdown sections.

This should also allow us to take advantage of the markdown_inline
parser for later changes, which is nice.
@MeanderingProgrammer
Copy link
Owner

This should be resolved with the following change: e64255d.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants