Skip to content

Commit bfd67f1

Browse files
fix: use nil if bg is missing in bg_as_fg
## Details This should improve behavior with transparent color schemes based on past issues / discussions. Unsure if it handles all situations but should generally improve default behaviors. If the `bg` value we are attempting to pull from a highlight group is missing the generated highlight is labelled as not `visible`, in which case we return `nil` rather than the actual highlight group. Update the logic to handle `nil` values, only needed to be done when generating fenced code block border.
1 parent 475d3ad commit bfd67f1

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- left padding for checkboxes [da260dd](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/da260dd4979d130f0dfc63e824c9cb2433cfded2)
1111
- dash width function [#537](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/537)
1212
[691651d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/691651de4e02cbea9ff50c62d7d3a679abc95564)
13+
- implement preview split [72f658d](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/72f658d7c506fff6a10bee4e7fa2af081f91489b)
1314

1415
### Bug Fixes
1516

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 October 16
1+
*render-markdown.txt* For NVIM v0.11.4 Last change: 2025 October 24
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

lua/render-markdown/core/colors.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ M.colors = {
6969
M.cache = {}
7070
---@type table<string, { fg: string, bg: string }>
7171
M.cache.combine = {}
72-
---@type table<string, { hl: string }>
72+
---@type table<string, { hl: string, visible: boolean }>
7373
M.cache.bg_as_fg = {}
7474

7575
---called from plugin directory
@@ -118,7 +118,7 @@ end
118118

119119
---@param highlight string
120120
---@param force? boolean
121-
---@return string
121+
---@return string?
122122
function M.bg_as_fg(highlight, force)
123123
local name = ('%s_%s_bg_as_fg'):format(M.prefix, highlight)
124124
if not M.cache.bg_as_fg[name] or force then
@@ -127,9 +127,9 @@ function M.bg_as_fg(highlight, force)
127127
fg = hl.bg,
128128
ctermfg = hl.ctermbg,
129129
})
130-
M.cache.bg_as_fg[name] = { hl = highlight }
130+
M.cache.bg_as_fg[name] = { hl = highlight, visible = hl.bg ~= nil }
131131
end
132-
return name
132+
return M.cache.bg_as_fg[name].visible and name or nil
133133
end
134134

135135
---@private

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ local state = require('render-markdown.state')
66
local M = {}
77

88
---@private
9-
M.version = '8.9.9'
9+
M.version = '8.9.10'
1010

1111
function M.check()
1212
M.start('versions')

lua/render-markdown/render/markdown/code.lua

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,23 +175,28 @@ end
175175
---@param thin string
176176
function Render:border(node, thin)
177177
local kind = self.config.border
178-
local highlight = self.config.highlight_border
178+
if kind == 'none' or not node then
179+
return
180+
end
179181
if kind == 'hide' then
180182
self.marks:over(self.config, true, node, { conceal_lines = '' })
181-
elseif kind == 'none' or not node or not highlight then
182-
-- do nothing
183-
else
184-
local icon = kind == 'thin' and thin or ' '
185-
if icon ~= ' ' then
186-
highlight = colors.bg_as_fg(highlight)
187-
end
188-
local block = self.config.width == 'block'
189-
local width = block and self.data.body - node.start_col or vim.o.columns
190-
self.marks:start(self.config, 'code_border', node, {
191-
virt_text = { { icon:rep(width), highlight } },
192-
virt_text_pos = 'overlay',
193-
})
183+
return
194184
end
185+
local highlight = self.config.highlight_border or nil
186+
if not highlight then
187+
return
188+
end
189+
local icon = kind == 'thin' and thin or ' '
190+
highlight = icon == ' ' and highlight or colors.bg_as_fg(highlight)
191+
if not highlight then
192+
return
193+
end
194+
local block = self.config.width == 'block'
195+
local width = block and self.data.body - node.start_col or vim.o.columns
196+
self.marks:start(self.config, 'code_border', node, {
197+
virt_text = { { icon:rep(width), highlight } },
198+
virt_text_pos = 'overlay',
199+
})
195200
end
196201

197202
---@private

0 commit comments

Comments
 (0)