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

How to auto-display images when opening a md file? #45

Open
xorbuht opened this issue Aug 11, 2024 · 3 comments
Open

How to auto-display images when opening a md file? #45

xorbuht opened this issue Aug 11, 2024 · 3 comments

Comments

@xorbuht
Copy link

xorbuht commented Aug 11, 2024

When I first open a markdown file with embedded images, it does not display these images. However it does leave empty space for these images to be displayed. It starts to display an image only after I edit a line with the link to the image.
How do I auto-display images in a markdown file after I open it?

@xorbuht
Copy link
Author

xorbuht commented Aug 16, 2024

I've asked a Claude AI for help. It adviced me to modify the file ~/.local/share/nvim/lazy/hologram.nvim/lua/hologram/init.lua by adding the following code inside function hologram.setup(opts). Now it works as I wanted:

        vim.api.nvim_create_autocmd({"BufReadPost"}, {
            pattern = {"*.md", "*.markdown"},
            callback = function(au)
                vim.schedule(function()
                    hologram.buf_generate_images(au.buf, 0, -1)
                    hologram.buf_render_images(au.buf, 0, -1)
                end)
            end,
            group = augroup
        })

@xorbuht
Copy link
Author

xorbuht commented Aug 16, 2024

After some testing found that it does not always work. Sometimes pics briefly appear, then disappear.

@zhuosongz
Copy link

I got an error after I copy your codes in my setup function: Error executing vim.schedule lua callback: ...ocal/share/nvim/lazy/hologram.nvim/lua/hologram/init.lua:47: Invalid buffer id: 13

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

2 participants