From 26d5a637fd70841584f54389f909565ab3aa3932 Mon Sep 17 00:00:00 2001 From: delphinus Date: Fri, 15 May 2026 15:42:56 +0900 Subject: [PATCH] fix(highlight): carry over bg from treesitter heading hl setup_heading_highlights only copied fg from @markup.heading..markdown, dropping bg and other attributes. Colorschemes that paint a heading background (e.g. tokyonight defines distinct bg per level) appeared with bg in the source buffer but not in the preview buffer. Now copy the full attribute table from the resolved treesitter hl, so bg, italic, underline, etc. all propagate. bold = true is still forced as a fallback for colorschemes that omit it. Co-Authored-By: Claude Opus 4.7 (1M context) --- lua/md-render/init.lua | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lua/md-render/init.lua b/lua/md-render/init.lua index 17147b9..f750367 100644 --- a/lua/md-render/init.lua +++ b/lua/md-render/init.lua @@ -31,14 +31,21 @@ local function blend_color(fg, bg, alpha) return bit.lshift(r, 16) + bit.lshift(g, 8) + b end ---- Set up heading highlight groups (MdRenderH1..MdRenderH6) +--- Set up heading highlight groups (MdRenderH1..MdRenderH6). +--- All attributes from `@markup.heading..markdown` are carried over +--- (including `bg`, `italic`, `underline`, etc.) so colorschemes that paint +--- a heading background (e.g. tokyonight) render the same way in the +--- preview buffer as in the source buffer. `bold` is forced as a fallback +--- for colorschemes that omit it. function M.setup_heading_highlights() for level = 1, 6 do local hl_name = "MdRenderH" .. level local ts_name = "@markup.heading." .. level .. ".markdown" local ts_hl = vim.api.nvim_get_hl(0, { name = ts_name, link = false }) - if ts_hl.fg then - vim.api.nvim_set_hl(0, hl_name, { fg = ts_hl.fg, bold = true, default = true }) + if ts_hl.fg or ts_hl.bg then + ts_hl.bold = true + ts_hl.default = true + vim.api.nvim_set_hl(0, hl_name, ts_hl) else vim.api.nvim_set_hl(0, hl_name, { link = "Title", default = true }) end