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

Render HTML images in markdown files #234

Open
linkarzu opened this issue Oct 30, 2024 · 5 comments
Open

Render HTML images in markdown files #234

linkarzu opened this issue Oct 30, 2024 · 5 comments

Comments

@linkarzu
Copy link
Contributor

If I open an HTML or CSS file I can render the images in them because of these options

          html = {
            enabled = true,
          },

          css = {
            enabled = true,
          },

So in my html file I do see the following image rendered

<img
  src="https://res.cloudinary.com/daqwsgmx6/image/upload/q_75/v1717456413/youtube/neovim/neovim-vs-neovide.avif"
  alt="neovide-vs-neovim"
/>

But if in a markdown file, I cannot render HTML images, is it possible to have the option, to render HTML images in markdown files? I guess not everyone would like to have it on by default

I originally asked about this in discord 16 days ago, and I said I would open this issue in a "little while", this is a little while 🤣 (sorry but my procrastinating skills and random change in priorities don't allow me to focus)

@3rd
Copy link
Owner

3rd commented Oct 30, 2024

Hey, just had a look ^_^
You can enable the HTML integration for markdown files as well and it should work.

          integrations = {
            html = {
              filetypes = { "html", "xhtml", "htm", "markdown" },
            },
          },

image

@linkarzu
Copy link
Contributor Author

linkarzu commented Oct 30, 2024

Nice, I just tested it and it works, so it was there all along, sorry!
I tried the other way around, I added html as a filetime filetype to the markdown extension, but that was not correct.
I also enabled the only_render_image_at_cursor = true, which is great
so for context in case someone in the future comes asking the same question, this is what it looks like for me:

        integrations = {
          -- This is disabled by default
          -- Detect and render images referenced in HTML files
          -- Make sure you have an html treesitter parser installed
          -- ~/github/dotfiles-latest/neovim/neobean/lua/plugins/treesitter.lua
          html = {
            enabled = true,
            only_render_image_at_cursor = true,
            -- Enabling "markdown" down here allows you to view html images in
            -- markdown files
            filetypes = { "html", "xhtml", "htm", "markdown" },
          },

Again, thanks for all your time and work @3rd, this can be closed

@linkarzu linkarzu reopened this Nov 10, 2024
@linkarzu
Copy link
Contributor Author

  • Hey, hope you're having a great day, setting the html integration to render markdown files gave me some issues
  • I just realized a few days ago that my markdown files were extremely slow, I thought it was the render-markdown plugin, then I thought it was my lualine config, then I thought copilot, so disabled copilot in markdown files, but nothing fixed it
  • Then this error popped up, but I never really payed attention to it, just ignored it and kept doing my stuff
   Error  04:59:13 msg_show.lua_error Error executing vim.schedule lua callback: ...eovim/0.10.2_1/share/nvim/runtime/lua/vim/treesitter.lua:198: Index out of bounds
stack traceback:
	[C]: in function 'nvim_buf_get_text'
	...eovim/0.10.2_1/share/nvim/runtime/lua/vim/treesitter.lua:198: in function 'get_node_text'
	...0.10.2_1/share/nvim/runtime/lua/vim/treesitter/query.lua:273: in function 'handler'
	...0.10.2_1/share/nvim/runtime/lua/vim/treesitter/query.lua:767: in function 'fn'
	...im/0.10.2_1/share/nvim/runtime/lua/vim/func/_memoize.lua:58: in function 'match_preds'
	...0.10.2_1/share/nvim/runtime/lua/vim/treesitter/query.lua:883: in function '(for generator)'
	.../neobean/lazy/image.nvim/lua/image/integrations/html.lua:25: in function 'query_buffer_images'
	...are/neobean/lazy/image.nvim/lua/image/utils/document.lua:45: in function ''
	vim/_editor.lua: in function <vim/_editor.lua:0>
  • So disabled image.nvim and that fixed the issue
  • Then I re-enabled the plugin and removed markdown from the html integration
          html = {
            enabled = true,
            only_render_image_at_cursor = true,
            -- Enabling "markdown" below allows you to view html images in .md files
            -- https://github.com/3rd/image.nvim/issues/234
            -- filetypes = { "html", "xhtml", "htm", "markdown" },
            filetypes = { "html", "xhtml", "htm" },
          },
  • So if someone else is thinking of enabling it, keep this in mind, your markdown files will slow to a crawl
  • Is this because the html treesitter parser is not compatible with md files?
  • Shouldn't the markdown integration support HTML files instead of the HTML integration support markdown files?
  • Any help would be appreciated, and thanks for all the help received so far 🙂

@3rd
Copy link
Owner

3rd commented Nov 10, 2024

Hey, that's very interesting! Didn't expect the html parser to have any issues with markdown files, do you have a sample file?

@UnaTried
Copy link
Contributor

UnaTried commented Feb 28, 2025

Its in all parsers (I tested, I am currently making a PR @3rd and @linkarzu

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

No branches or pull requests

3 participants