-- In-buffer markdown rendering: headings, code blocks, tables, callouts and -- checkboxes rendered in place, in the one buffer. No preview window or split. -- The cursor line keeps its raw syntax (the plugin's anti_conceal), so editing -- is unaffected. mt toggles rendering for the current buffer. return { { "MeanderingProgrammer/render-markdown.nvim", ft = { "markdown" }, dependencies = { "nvim-tree/nvim-web-devicons" }, opts = {}, config = function(_, opts) require("render-markdown").setup(opts) -- render-markdown takes its per-level heading colours from the -- treesitter captures @markup.heading.{1..6}.markdown. None of the -- colourschemes under config/nvim/colors/ define treesitter groups -- at all -- happy_hacking, onehalfdark and ayu were each checked -- -- so those captures resolve to nothing and every heading level -- renders with no colour. Supply a ramp, but only where the theme -- left the group undefined, so a theme that does define them keeps -- its own. Re-applied on ColorScheme, since cfg-watch switches the -- theme at runtime and `:colorscheme` can clear highlight groups. local ramps = { dark = { { "#F3F2CC", 230 }, { "#FAD566", 221 }, { "#B3EBBF", 157 }, { "#81A2C7", 103 }, { "#F77EBD", 211 }, { "#fcb280", 179 }, }, light = { { "#2F2F2F", 236 }, { "#8C6D1F", 136 }, { "#3F6B3F", 22 }, { "#3A5A8C", 24 }, { "#8C3A6B", 89 }, { "#8C5A2F", 130 }, }, } local function set_heading_colors() local ramp = ramps[vim.o.background] or ramps.dark for level = 1, 6 do local name = "RenderMarkdownH" .. level -- Put render-markdown's own link back first, so a theme that -- does define the capture wins, and so this stays correct -- after a theme switch. vim.api.nvim_set_hl(0, name, { link = "@markup.heading." .. level .. ".markdown" }) local hl = vim.api.nvim_get_hl(0, { name = name }) if not (hl.fg or hl.bg or hl.bold or hl.italic or hl.underline) then vim.api.nvim_set_hl(0, name, { fg = ramp[level][1], ctermfg = ramp[level][2], bold = true, }) end end end set_heading_colors() vim.api.nvim_create_autocmd("ColorScheme", { callback = set_heading_colors }) vim.api.nvim_create_autocmd("FileType", { pattern = "markdown", callback = function(event) vim.keymap.set("n", "mt", "RenderMarkdown buf_toggle", { buffer = event.buf, desc = "Toggle markdown rendering", }) end, }) end, }, }