diff options
| author | Igor Soarez <igor@soarez.org> | 2026-10-07 19:24:51 +0300 |
|---|---|---|
| committer | Igor Soarez <igor@soarez.org> | 2026-10-07 19:24:51 +0300 |
| commit | fdaf6742b0823b088c58ac8e26f6556a0c12c43f (patch) | |
| tree | 430247857d520bc18e6e7fbb43d8b84d0b92d719 /config | |
| parent | 6c97cb32cb21beb265a3d5b2b72a92aed52f9040 (diff) | |
nvim: render markdown in the buffer
render-markdown.nvim draws headings, code blocks, tables and checkboxes in
place, in the one buffer, and leaves the cursor line raw so editing is
unaffected; <leader>mt toggles it. The markdown and markdown_inline parsers
join the install list, which also gives noice's LSP hover rendering the
parsers it was already set up to use.
None of the colourschemes here define the @markup.heading.N.markdown captures
the plugin colours headings from, so every level rendered alike. A ramp fills
them in, only where the theme left the group empty, and again on each theme
switch. Checked with the real config: 26 marks on a test file, conceallevel 3,
H1-H3 in distinct bold colours.
AGENTS.md also stops listing nvim as having no machine-local hook: lua/local.lua
is one, gitignored and loaded by cfg-watch after the plugins.
From change request 12882c.
Diffstat (limited to 'config')
| -rw-r--r-- | config/nvim/lua/plugins/lsp.lua | 1 | ||||
| -rw-r--r-- | config/nvim/lua/plugins/markdown.lua | 73 |
2 files changed, 74 insertions, 0 deletions
diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index c3853b3..1470177 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -128,6 +128,7 @@ return { local TS = require("nvim-treesitter") local ensure_installed = { "astro", "go", "html", "javascript", "lua", "python", "tsx", "typescript", + "markdown", "markdown_inline", } local installed = TS.get_installed("parsers") local to_install = vim.tbl_filter(function(lang) diff --git a/config/nvim/lua/plugins/markdown.lua b/config/nvim/lua/plugins/markdown.lua new file mode 100644 index 0000000..b298554 --- /dev/null +++ b/config/nvim/lua/plugins/markdown.lua @@ -0,0 +1,73 @@ +-- 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. <leader>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", "<leader>mt", "<cmd>RenderMarkdown buf_toggle<cr>", { + buffer = event.buf, + desc = "Toggle markdown rendering", + }) + end, + }) + end, + }, +} |
