Render HTML images in markdown files
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)
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" },
},
},
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
- 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
markdownfrom 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 🙂
Hey, that's very interesting! Didn't expect the html parser to have any issues with markdown files, do you have a sample file?
Its in all parsers (I tested, I am currently making a PR @3rd and @linkarzu