markdown.nvim icon indicating copy to clipboard operation
markdown.nvim copied to clipboard

help: Render-markdown does not start when opening a markdown file directly

Open armfem opened this issue 3 months ago • 24 comments

Neovim version (nvim -v)

0.11.4

Neovim distribution

N/A

Description

When opening a file as nvim file.md the Lazy configuration has it as not loaded. Nevertheless, if i open neovim as nvim and then :tabnew file.md it render kind of okey (code highlight is not fine, but sometimes is but most of the times it isnt).

When render-markdown is on, :checkhealth render-markdown gives the following output


==============================================================================
render-markdown:                                                          1 ❌

render-markdown.nvim [versions] ~
- ✅ OK neovim >= 0.11
- ✅ OK tree-sitter ABI: 15
- ✅ OK plugin: 8.7.15

render-markdown.nvim [configuration] ~
- ✅ OK valid

render-markdown.nvim [tree-sitter markdown] ~
- ✅ OK parser: installed
- ✅ OK ABI: 15
- ✅ OK highlights: ~/.local/share/nvim/lazy/nvim-treesitter/queries/markdown/highlights.scm
- ❌ ERROR highlighter: not enabled
  - ADVICE:
    - call vim.treesitter.start on markdown buffers

render-markdown.nvim [tree-sitter markdown_inline] ~
- ✅ OK parser: installed
- ✅ OK ABI: 14
- ✅ OK highlights: ~/.local/share/nvim/lazy/nvim-treesitter/queries/markdown_inline/highlights.scm

render-markdown.nvim [tree-sitter html] ~
- ✅ OK parser: installed
- ✅ OK ABI: 14

render-markdown.nvim [tree-sitter yaml] ~
- ✅ OK parser: installed
- ✅ OK ABI: 14

render-markdown.nvim [icons] ~
- ✅ OK using: nvim-web-devicons

render-markdown.nvim [executables] ~

render-markdown.nvim [conflicts] ~
- ✅ OK headlines: not installed
- ✅ OK markview: not installed
- ✅ OK obsidian: not installed

My render markdown configuration is

return {
	"MeanderingProgrammer/render-markdown.nvim",
	enabled = true,
	dependencies = { "nvim-treesitter/nvim-treesitter", "nvim-tree/nvim-web-devicons" },
	ft = "markdown",

	---@module 'render-markdown'
	---@type render.md.UserConfig
	opts = {
		render_modes = { "n", "c", "t" },
		completions = { blink = { enabled = true } },
		latex = { enabled = false },
		code = {
			border = "thick",
		},
	},
}

I try making it to work okey but I cannot find the error or now enough neovim/plugin/lua to start debugging properly. If there are any ideas or something I am missing, tried searching documentation and old issues but could not find anything.

Cheers, Armando

armfem avatar Sep 03 '25 22:09 armfem

Same issue, or more accurately "not-much-of-an-issue" in that the error seems to be in checkhealth. As reported above checkhealth reports

render-markdown.nvim [tree-sitter markdown] ~
- ✅ OK parser: installed
- ✅ OK ABI: 15
- ✅ OK highlights: ~/.local/share/nvim/site/queries/markdown/highlights.scm
- ❌ ERROR highlighter: not enabled
  - ADVICE:
    - call vim.treesitter.start on markdown buffers

render-markdown.nvim [tree-sitter markdown_inline] ~
- ✅ OK parser: installed
- ✅ OK ABI: 15
- ✅ OK highlights: ~/.local/share/nvim/site/queries/markdown_inline/highlights.scm

yet markdown files are rendered correctly. Of possible interest is if I perform the same test that checkhealth does on a markdown buffer := vim.treesitter.highlighter.active[61] where 61 is the buffer containing a markdown file I get the desired non-nil response.

nvim v-0.12.0-dev nvim-treesitter main (not master) branch Filetype autocmd that loads treesitter for most buffers

NB: checkhealth output was the same before I switched to the main nvim-treesitter branch. It's only now that I decided to take a look.

Edit: I think checkhealth doesn't see highlights loaded as my autocmd to start treesitter does so only after awaiting the language to be installed (if necessary).

marchyman avatar Sep 05 '25 03:09 marchyman

When opening a file as nvim file.md the Lazy configuration has it as not loaded.

Can you explain what you mean by this. Are you saying if you open some markdown file using nvim README.md when the file opens nothing gets rendered, so headings don't have icons, etc. I'm trying to understand if the issue is related to general treesitter highlighting, this plugin, or something else.

A screenshot showing the current result and what you expect versus what you're seeing would be very helpful, just to have a concrete example of the problem.

MeanderingProgrammer avatar Sep 07 '25 19:09 MeanderingProgrammer

I also constantly face this problem. But what's the reason - I don't understand. As example:

nvim latex.md

Image

The title renders normally, but the first line is not (and so almost always!)

LexeyKhom avatar Sep 08 '25 17:09 LexeyKhom

I'm still not sure I entirely see the issue, is it that the **Hidden** text is not in bold and the asterisks are not concealed?

In theory that should have nothing to do with this plugin, that's all up to the highlighter. If you disable this plugin does the issue go away?

MeanderingProgrammer avatar Sep 09 '25 03:09 MeanderingProgrammer

Updated to the latest version and set the settings for the default settings:

return {
  "MeanderingProgrammer/render-markdown.nvim",
  ft = { "markdown", "Avante" },
  dependencies = {
    "nvim-treesitter/nvim-treesitter",
    "nvim-tree/nvim-web-devicons",
  }
}

The problem does not always arise. Sometimes it renders normally.

cmd: nvim latex.md

With plugin:

Image

Without plugin (always ok):

Image

I also noticed that the bug occurs the more often, the larger the document. In the document above, it occurs in 6/10 cases. The document is lower in 2/10 cases. In general, for me, the mistake is insignificant. But the author of the post can be much worse.

Image

LexeyKhom avatar Sep 09 '25 04:09 LexeyKhom

Hmm, I'm still not able to replicate this behavior on my end, really regardless of file size or contents, but there could be many reasons for that.

Would you be up able to create a minimal example that reproduces the issue for you? Here's a starting minit.lua file:

local lazypath = vim.fn.stdpath('data') .. '/lazy/lazy.nvim'
assert(vim.uv.fs_stat(lazypath))
vim.opt.rtp:prepend(lazypath)

require('lazy').setup({
    {
        'nvim-treesitter/nvim-treesitter',
        branch = 'main',
        build = ':TSUpdate',
        config = function()
            require('nvim-treesitter').install({ 'markdown', 'markdown_inline' })
            vim.api.nvim_create_autocmd('FileType', {
                group = vim.api.nvim_create_augroup('Highlighter', {}),
                pattern = 'markdown',
                callback = function(args)
                    vim.treesitter.start(args.buf)
                end,
            })
        end,
    },
    {
        'MeanderingProgrammer/render-markdown.nvim',
        dependencies = { 'nvim-treesitter/nvim-treesitter' },
        config = function()
            require('render-markdown').setup({})
        end,
    },
})

Then open a file using: nvim --clean -u minit.lua latex.md

Right now it sets no options, does not do any lazy loading, and only enables highlighting on markdown buffers.

From here you can add more plugins, set additional options, and do whatever else you need to until the issue occurs again. Hopefully from there we can isolate the problem.

MeanderingProgrammer avatar Sep 09 '25 05:09 MeanderingProgrammer

Current global configuration:

vim.keymap.set('n', "<A-q>",  "<cmd> q <CR>", { nowait = true })

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
assert(vim.uv.fs_stat(lazypath))
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-treesitter/nvim-treesitter",
		branch = "main",
		build = ":TSUpdate",
		opts = function()
			return {
				ensure_installed = require("utils.loader").langs("tree"),
				auto_install = true,
			}
		end,
		config = function()
			-- require('nvim-treesitter').install({ 'markdown', 'markdown_inline' })
			vim.api.nvim_create_autocmd("FileType", {
				group = vim.api.nvim_create_augroup("Highlighter", {}),
				pattern = "markdown",
				callback = function(args)
					vim.treesitter.start(args.buf)
				end,
			})
		end,
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter" },
		config = function()
			require("render-markdown").setup({})
		end,
	},
})

-- require('nvim-treesitter').install({ 'markdown', 'markdown_inline' }) - does not work for me, so I use:

    opts = function()
      return {
        ensure_installed = require("utils.loader").langs "tree",
        auto_install = true,
      }
    end

The bug still appears, but much less often. I had to double the file to catch it at least 1/10 times.

Image

LexeyKhom avatar Sep 09 '25 06:09 LexeyKhom

But when using the same configuration with minit.lua and the command nvim --clean -u minit.lua latex.md, no bug occurs.

So, perhaps, my problem is in the cache and it is worthwhile to reinstall the configuration. What about the author of the post - I do not know.

LexeyKhom avatar Sep 09 '25 06:09 LexeyKhom

After reinstalling (rm -rf ~/.local/share/nvim/) everything works fine for me.

Image

LexeyKhom avatar Sep 09 '25 06:09 LexeyKhom

Huh, would be nice to get some idea of what's going on. The minimal configuration should also be impacted by the state of ~/.local/share/nvim/, since it still uses that directory. If someone is able to create a version of minit.lua that still produces the issue I can take a look. Otherwise it could be some weird state thing going on and deleting everything might help.

MeanderingProgrammer avatar Sep 09 '25 09:09 MeanderingProgrammer

And... it returned.

Image

With nvim --clean -u minit.lua latex.md too.

Image

I don't know what's the matter.

LexeyKhom avatar Sep 10 '25 10:09 LexeyKhom

Can you paste your minit.lua file with any changes you made.

MeanderingProgrammer avatar Sep 10 '25 17:09 MeanderingProgrammer

minit.lua:

vim.keymap.set('n', "<A-q>",  "<cmd> q <CR>", { nowait = true })

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
assert(vim.uv.fs_stat(lazypath))
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-treesitter/nvim-treesitter",
		branch = "main",
		build = ":TSUpdate",
		opts = function()
			return {
				ensure_installed = require("utils.loader").langs("tree"),
				auto_install = true,
			}
		end,
		config = function()
			-- require('nvim-treesitter').install({ 'markdown', 'markdown_inline' })
			vim.api.nvim_create_autocmd("FileType", {
				group = vim.api.nvim_create_augroup("Highlighter", {}),
				pattern = "markdown",
				callback = function(args)
					vim.treesitter.start(args.buf)
				end,
			})
		end,
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter" },
		config = function()
			require("render-markdown").setup({})
		end,
	},
})

latex.md: (just as example)

# Latex test

1. **Hidden** \__symbols_`:` $A = \begin{pmatrix}a& b\\& \\c& d\end{pmatrix}$.
   - _italic_: $A = \begin{pmatrix}a\\c\end{pmatrix}$.
   - **bold**: $A = \begin{pmatrix}a\\c\end{pmatrix}$.
   - `code` $A = \begin{pmatrix}a\\c\end{pmatrix}$
   - \*\*not bold\*\* $A = \begin{pmatrix}a\\c\end{pmatrix}$
   - **Hidden symbols in another line** _lorem ipsum dolor amet lorem **ipsum
     dolor** amet_: $A = \begin{pmatrix}a& b\\& \\c& d\end{pmatrix}$.

2. Two or more multi-line formulas in one virtual line (combine):
   - if $\frac{a}{b}$ = $\frac{c}{d}$ = $\frac{e}{f}$
   - $\begin{pmatrix}a\\c\end{pmatrix}$ and $\begin{pmatrix}b\\d\\e\end{pmatrix}$

3. Non-ASCII symbols:
   - "ыыы₁₁₁" $A = \begin{pmatrix}a& b\\& \\c& d\end{pmatrix}$.
   - $\begin{pmatrix}a₁\\a₂\end{pmatrix}$ and $\begin{pmatrix}b₁\\b₂\\b₃\end{pmatrix}$

4. Different height: (not working in nabla)
   - $\begin{pmatrix}a₁\\a₂\end{pmatrix}$ and $\frac{ \sum_{i=0}^{N} (X_i - \bar{X})^2 }{ \prod_{j=1}^{M} \frac{1}{j!} }$ and $\begin{pmatrix} \text{Very} \\ \text{many} \\ \text{lines} \\ \text{in} \\ \text{matrix} \end{pmatrix}$.

5. Multi-line formula: (not working)
   - with `$`:
     $A = \begin{pmatrix} a₁ & b₁ \\ & \\a₂&b₂\end{pmatrix}
     = \begin{pmatrix}c₁\\ \\ c₂\end{pmatrix}$
   - with `$$`:
     $$
     A = \begin{pmatrix} a₁ & b₁ \\ & \\a₂&b₂\end{pmatrix}
       = \begin{pmatrix}c₁\\ \\ c₂\end{pmatrix}
     $$

$last node$

cmd: nvim --clean -u minit.lua latex.md

Also sometimes it breaks on the 2nd or 3rd line. For example, like here on the line "bold"

Image

LexeyKhom avatar Sep 10 '25 18:09 LexeyKhom

Oh, sorry. There is my internal library "utils.loader" used in the file. But it is quite simple and should not cause errors (it just collects language settings from files). You can simply replace it with "markdown", "markdown_inline" etc. Unfortunately, I literally just turned off the computer and will not be able to fix and test it correctly.

LexeyKhom avatar Sep 10 '25 18:09 LexeyKhom

Update:

minit.lua: (without my libs)

vim.keymap.set("n", "<A-q>", "<cmd> q <CR>", { nowait = true })

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
assert(vim.uv.fs_stat(lazypath))
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-treesitter/nvim-treesitter",
		branch = "main",
		build = ":TSUpdate",
		opts = function()
			return {
				ensure_installed = { "markdown", "markdown_inline" },
				auto_install = true,
			}
		end,
		config = function()
			vim.api.nvim_create_autocmd("FileType", {
				group = vim.api.nvim_create_augroup("Highlighter", {}),
				pattern = "markdown",
				callback = function(args)
					vim.treesitter.start(args.buf)
				end,
			})
		end,
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter" },
		config = function()
			require("render-markdown").setup({})
		end,
	},
})

Same result:

Image

ABSOLUTELY pure nvim cmd XDG_DATA_HOME=~/Documents/NeoVim/.local/share XDG_CONFIG_HOME=~/Documents/NeoVim/ nvim latex.md (NeoVim folder has only one folder "nvim" with only one file "init.lua")

init.lua:

vim.keymap.set("n", "<A-q>", "<cmd> q <CR>", { nowait = true })

local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
---@diagnostic disable-next-line: undefined-field (fs_stat)
if not (vim.uv or vim.loop).fs_stat(lazypath) then
	local out = vim.fn.system({
		"git",
		"clone",
		"--filter=blob:none",
		"--branch=stable",
		lazyrepo,
		lazypath,
	})
	if vim.v.shell_error ~= 0 then
		vim.api.nvim_echo({
			{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
			{ out, "WarningMsg" },
			{ "\nPress any key to exit..." },
		}, true, {})
		vim.fn.getchar()
		os.exit(1)
	end
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
	{
		"nvim-treesitter/nvim-treesitter",
		branch = "main",
		build = ":TSUpdate",
		opts = function()
			return {
				ensure_installed = { "markdown", "markdown_inline" },
				auto_install = true,
			}
		end,
		config = function()
			vim.api.nvim_create_autocmd("FileType", {
				group = vim.api.nvim_create_augroup("Highlighter", {}),
				pattern = "markdown",
				callback = function(args)
					vim.treesitter.start(args.buf)
				end,
			})
		end,
	},
	{
		"MeanderingProgrammer/render-markdown.nvim",
		dependencies = { "nvim-treesitter/nvim-treesitter" },
		config = function()
			require("render-markdown").setup({})
		end,
	},
})

Same issue (but on line **Hidden symbols in another line**):

Image

But more often than not it renders fine:

Image

LexeyKhom avatar Sep 10 '25 19:09 LexeyKhom

Sorry for not getting back any sooner. In my case I did some changes to the treesitter configuration and found out that the problem also did happen for other files (.py, .json, .php, etc...). After some looking around for a solution, I found this work around in the form of a keymap to be used when opening neovim.

keymap(
	"n",
	"<leader>rh",
	"<cmd>write | edit | TSBufEnable highlight<CR>",
	{ desc = "Restore highlight in buffer if not working fine." }
)

It is sub-optimal, but it works for the moment and I was getting tired of searching I cant seem to find the issue that point me to this solution. I'll try to give it to you as soon as I find it again :) Hope this helps!

armfem avatar Sep 21 '25 15:09 armfem

Found it ! https://github.com/nvim-treesitter/nvim-treesitter/issues/78

I do not really understand what is going on, and since Im not very lua/neovim fluently cant ready decipher the problem. Nevertheless, this gives me a working neovim which is enough.

armfem avatar Sep 21 '25 15:09 armfem

Hmm, that's a pretty old issue, hard to really say if it's related since a lot of this logic has been upstreamed into neovim itself and has likely changed along the way. I also don't see the suggestion to call TSBufEnable, but it makes sense since it restarts the highlighter.

I actually have a patch to do this as part of this plugin, it's gated behind the restart_highlighter option. You can enable it with:

require('render-markdown').setup({
    restart_highlighter = true,
})

Which should "fix" the problem in markdown buffers, but the problem will remain in other filetypes.

It would be good to know what's really going on here, I can't replicate the issue on my end so don't really have a place to start. Something is causing this weird state to happen, and maybe there's something we could do to actually resolve the problem, but it also could just be a thing that happens that there's no current solution for :( Maybe some edge case related to all the recent async changes?

MeanderingProgrammer avatar Sep 22 '25 17:09 MeanderingProgrammer

I am trying to simplify my neovim config, remove plugins I do not really use and stuff. Once that is over, and if the problem still persist I'll try to give it another look.

In the meantime, ff there is anything I can do to help (logs or something) I will gladly spend the time on it ( I really like render-markdown plugin so it is the least I can do :)

armfem avatar Sep 24 '25 17:09 armfem

I am facing this issue as well. I have recently switched to obisidian-nvim/obsidian.nvim (was using epwalsh's repo before) and also I moved to fzf-lua from telescope and blink from cmp. A lot of moving pieces so I'm not sure what might be causing this issue. For me it's always happening (not randomly) but setting restart_highlighter = true temporarily fixed it.

Let me know if I can be of any help understanding what the issue might be

tobiabocchi avatar Oct 31 '25 16:10 tobiabocchi

@tobiabocchi, just to clarify this plugin does not start when you open a markdown file consistently? Is it only the first markdown file file? Any more details about what's going on as a general pattern would be helpful. Also are you lazy loading this plugin, and if you disable lazy loading for this plugin does the problem still occur?

MeanderingProgrammer avatar Oct 31 '25 18:10 MeanderingProgrammer

In my case, it is indeed only the first markdown file afterwards it is fine. I had lazy loading activated, but remove it to test.

armfem avatar Oct 31 '25 21:10 armfem

@MeanderingProgrammer In my case the plugin always seems to start successfully. The problem is with syntax highlighting within code blocks. It's not working, setting restart_highlighter = true temporarily fixed it but now syntax highlighting in code blocks is not working again

tobiabocchi avatar Nov 07 '25 09:11 tobiabocchi

My plugin doesn't really have anything to do with the syntax highlighting in code blocks, does disabling this plugin resolve the issue for you?

MeanderingProgrammer avatar Nov 07 '25 23:11 MeanderingProgrammer