Skip to content

Commit a1fc4e5

Browse files
feat: separate code border highlight, allow false value
## Details Adds new `code.highlight_border` option which by default links to the general `RenderMarkdownCode` highlight to avoid visible changes. This value is used for both `thick` and `thin` borders as well as for the background of the language name / icon section. The value is also allowed to be a `boolean` (only a value of `false` makes sense but `true` will have the same behavior as `false`). If set to a `boolean` then no additional highlight is added for the language name / icon section and bottom borders will have the same behavior as the `none` value, i.e. they won't be rendered in any way. Having `code.highlight_border = false` is the most equivalent to the older behavior of `code.border = 'none'` which needed to be slightly modified to accommodate more `border` values. Setting both of these is a little redundant but up to the user.
1 parent e6c8081 commit a1fc4e5

13 files changed

+88
-50
lines changed

Diff for: CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,16 @@
1717
[8ee2701](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/8ee2701a6c4cdaef7ea0b27c13c26971ae3c9761)
1818
[7bf951b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/7bf951b8ad93d47b90be290be6fc60da5788ddaa)
1919
- code border for different conceal settings [e724a49](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/e724a49dee315744d6f5d3c651ddd604cc7afc52)
20+
- use builtin extends query in vim.treesitter.query.set for injections [c91fa46](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c91fa46fc8d79f5577beac70a459f30ec17a60c2)
21+
- completion filter for callouts and checkboxes [#380](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/380)
22+
[84d413b](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/84d413b0c432adaeaf3dcaac646638bd99d06aa6)
2023

2124
### Bug Fixes
2225

2326
- account for indent when right aligning code language [125258a](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/125258ac5bccd21651505d78dbd6120906243749)
27+
- support for code border for 0.11, disable conceal_lines highlights [#351](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/351)
28+
[#352](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/352)
29+
[e6c8081](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/e6c8081691881fd63b4d72cb472094ac190ac56e)
2430

2531
### Collaborator Shoutouts
2632

Diff for: README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -443,14 +443,16 @@ require('render-markdown').setup({
443443
above = '',
444444
-- Used below code blocks for thin border.
445445
below = '',
446+
-- Padding to add to the left & right of inline code.
447+
inline_pad = 0,
446448
-- Highlight for code blocks.
447449
highlight = 'RenderMarkdownCode',
448450
-- Highlight for language, overrides icon provider value.
449451
highlight_language = nil,
452+
-- Highlight for border, use false to add no highlight.
453+
highlight_border = 'RenderMarkdownCodeBorder',
450454
-- Highlight for language, used if icon provider does not have a value.
451455
highlight_fallback = 'RenderMarkdownCodeFallback',
452-
-- Padding to add to the left & right of inline code.
453-
inline_pad = 0,
454456
-- Highlight for inline code.
455457
highlight_inline = 'RenderMarkdownCodeInline',
456458
},
@@ -995,14 +997,16 @@ require('render-markdown').setup({
995997
above = '',
996998
-- Used below code blocks for thin border.
997999
below = '',
1000+
-- Padding to add to the left & right of inline code.
1001+
inline_pad = 0,
9981002
-- Highlight for code blocks.
9991003
highlight = 'RenderMarkdownCode',
10001004
-- Highlight for language, overrides icon provider value.
10011005
highlight_language = nil,
1006+
-- Highlight for border, use false to add no highlight.
1007+
highlight_border = 'RenderMarkdownCodeBorder',
10021008
-- Highlight for language, used if icon provider does not have a value.
10031009
highlight_fallback = 'RenderMarkdownCodeFallback',
1004-
-- Padding to add to the left & right of inline code.
1005-
inline_pad = 0,
10061010
-- Highlight for inline code.
10071011
highlight_inline = 'RenderMarkdownCodeInline',
10081012
},
@@ -1437,6 +1441,7 @@ The table below shows all the highlight groups with their default link
14371441
| RenderMarkdownH5Bg | DiffDelete | H5 background line |
14381442
| RenderMarkdownH6Bg | DiffDelete | H6 background line |
14391443
| RenderMarkdownCode | ColorColumn | Code block background |
1444+
| RenderMarkdownCodeBorder | RenderMarkdownCode | Code border background |
14401445
| RenderMarkdownCodeFallback | Normal | Fallback for code language |
14411446
| RenderMarkdownCodeInline | RenderMarkdownCode | Inline code background |
14421447
| RenderMarkdownInlineHighlight | RenderMarkdownCodeInline | Inline highlights contents |

Diff for: doc/render-markdown.txt

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2025 March 27
1+
*render-markdown.txt* For 0.10.0 Last change: 2025 March 28
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -508,14 +508,16 @@ Default Configuration ~
508508
above = '▄',
509509
-- Used below code blocks for thin border.
510510
below = '▀',
511+
-- Padding to add to the left & right of inline code.
512+
inline_pad = 0,
511513
-- Highlight for code blocks.
512514
highlight = 'RenderMarkdownCode',
513515
-- Highlight for language, overrides icon provider value.
514516
highlight_language = nil,
517+
-- Highlight for border, use false to add no highlight.
518+
highlight_border = 'RenderMarkdownCodeBorder',
515519
-- Highlight for language, used if icon provider does not have a value.
516520
highlight_fallback = 'RenderMarkdownCodeFallback',
517-
-- Padding to add to the left & right of inline code.
518-
inline_pad = 0,
519521
-- Highlight for inline code.
520522
highlight_inline = 'RenderMarkdownCodeInline',
521523
},
@@ -1054,14 +1056,16 @@ Code Block Configuration ~
10541056
above = '▄',
10551057
-- Used below code blocks for thin border.
10561058
below = '▀',
1059+
-- Padding to add to the left & right of inline code.
1060+
inline_pad = 0,
10571061
-- Highlight for code blocks.
10581062
highlight = 'RenderMarkdownCode',
10591063
-- Highlight for language, overrides icon provider value.
10601064
highlight_language = nil,
1065+
-- Highlight for border, use false to add no highlight.
1066+
highlight_border = 'RenderMarkdownCodeBorder',
10611067
-- Highlight for language, used if icon provider does not have a value.
10621068
highlight_fallback = 'RenderMarkdownCodeFallback',
1063-
-- Padding to add to the left & right of inline code.
1064-
inline_pad = 0,
10651069
-- Highlight for inline code.
10661070
highlight_inline = 'RenderMarkdownCodeInline',
10671071
},
@@ -1493,6 +1497,9 @@ The table below shows all the highlight groups with their default link
14931497
RenderMarkdownCode ColorColumn Code block
14941498
background
14951499

1500+
RenderMarkdownCodeBorder RenderMarkdownCode Code border
1501+
background
1502+
14961503
RenderMarkdownCodeFallback Normal Fallback for code
14971504
language
14981505

Diff for: lua/render-markdown/colors.lua

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ M.colors = {
3131
H6Bg = 'DiffDelete',
3232
-- Code
3333
Code = 'ColorColumn',
34+
CodeBorder = 'RenderMarkdownCode',
3435
CodeFallback = 'Normal',
3536
CodeInline = 'RenderMarkdownCode',
3637
-- General

Diff for: lua/render-markdown/health.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.1.21'
8+
M.version = '8.1.22'
99

1010
function M.check()
1111
M.start('version')

Diff for: lua/render-markdown/init.lua

+6-3
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,11 @@ local M = {}
233233
---@field border? render.md.code.Border
234234
---@field above? string
235235
---@field below? string
236+
---@field inline_pad? integer
236237
---@field highlight? string
237238
---@field highlight_language? string
239+
---@field highlight_border? string|boolean
238240
---@field highlight_fallback? string
239-
---@field inline_pad? integer
240241
---@field highlight_inline? string
241242

242243
---@class (exact) render.md.UserParagraph: render.md.UserBaseComponent
@@ -621,14 +622,16 @@ M.default_config = {
621622
above = '',
622623
-- Used below code blocks for thin border.
623624
below = '',
625+
-- Padding to add to the left & right of inline code.
626+
inline_pad = 0,
624627
-- Highlight for code blocks.
625628
highlight = 'RenderMarkdownCode',
626629
-- Highlight for language, overrides icon provider value.
627630
highlight_language = nil,
631+
-- Highlight for border, use false to add no highlight.
632+
highlight_border = 'RenderMarkdownCodeBorder',
628633
-- Highlight for language, used if icon provider does not have a value.
629634
highlight_fallback = 'RenderMarkdownCodeFallback',
630-
-- Padding to add to the left & right of inline code.
631-
inline_pad = 0,
632635
-- Highlight for inline code.
633636
highlight_inline = 'RenderMarkdownCodeInline',
634637
},

Diff for: lua/render-markdown/render/code.lua

+18-13
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ function Render:render()
100100

101101
local background = self:background_enabled(language)
102102
if background then
103-
self:background(start_row + 1, end_row - 1)
103+
self:background(start_row + 1, end_row - 1, self.code.highlight)
104104
end
105105
self:left_pad(background)
106106
end
@@ -117,6 +117,7 @@ function Render:language(language, delim)
117117
return false
118118
end
119119

120+
local border_highlight = self.code.highlight_border
120121
local padding = self.data.language_padding
121122

122123
local icon, icon_highlight = Icons.get(language.text)
@@ -137,8 +138,11 @@ function Render:language(language, delim)
137138
return false
138139
end
139140

140-
local highlight = { icon_highlight or self.code.highlight_fallback }
141-
table.insert(highlight, self.code.highlight)
141+
local highlight = {}
142+
table.insert(highlight, icon_highlight or self.code.highlight_fallback)
143+
if type(border_highlight) == 'string' then
144+
table.insert(highlight, border_highlight)
145+
end
142146

143147
if self.code.position == 'left' then
144148
text = Str.pad(padding) .. text
@@ -171,18 +175,18 @@ end
171175
---@param above boolean
172176
---@param empty boolean
173177
function Render:border(delim, above, empty)
174-
if self.code.border == 'none' or delim == nil then
178+
local highlight = self.code.highlight_border
179+
if self.code.border == 'none' or type(highlight) == 'boolean' or delim == nil then
175180
-- skip
176181
elseif self.code.border == 'thick' or not empty then
177-
self:background(delim.start_row, delim.start_row)
182+
self:background(delim.start_row, delim.start_row, highlight)
178183
elseif self.code.border == 'hide' and self.marks:over(true, delim, { conceal_lines = '' }) then
179184
-- successfully added
180185
else
181-
local width, highlight = self.data.width - self.data.col, self.code.highlight
182186
local border = above and self.code.above or self.code.below
183-
local line = { { border:rep(width), colors.bg_to_fg(highlight) } }
187+
local width = self.data.width - self.data.col
184188
self.marks:add('code_border', delim.start_row, self.data.col, {
185-
virt_text = line,
189+
virt_text = { { border:rep(width), colors.bg_to_fg(highlight) } },
186190
virt_text_pos = 'overlay',
187191
})
188192
end
@@ -196,17 +200,18 @@ function Render:background_enabled(language)
196200
return false
197201
end
198202
local disable = self.code.disable_background
199-
if type(disable) == 'table' then
200-
return language == nil or not vim.tbl_contains(disable, language.text)
201-
else
203+
if type(disable) == 'boolean' then
202204
return not disable
205+
else
206+
return language == nil or not vim.tbl_contains(disable, language.text)
203207
end
204208
end
205209

206210
---@private
207211
---@param start_row integer
208212
---@param end_row integer
209-
function Render:background(start_row, end_row)
213+
---@param highlight string
214+
function Render:background(start_row, end_row, highlight)
210215
local win_col, padding = 0, {}
211216
if self.code.width == 'block' then
212217
win_col = self.data.margin + self.data.max_width + self.data.indent
@@ -215,7 +220,7 @@ function Render:background(start_row, end_row)
215220
for row = start_row, end_row do
216221
self.marks:add('code_background', row, self.data.col, {
217222
end_row = row + 1,
218-
hl_group = self.code.highlight,
223+
hl_group = highlight,
219224
hl_eol = true,
220225
})
221226
if win_col > 0 and #padding > 0 then

Diff for: lua/render-markdown/state.lua

+1
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ function M.validate()
197197
:type('inline_pad', 'number')
198198
:type({ 'above', 'below', 'highlight', 'highlight_fallback', 'highlight_inline' }, 'string')
199199
:type('highlight_language', { 'string', 'nil' })
200+
:type('highlight_border', { 'string', 'boolean' })
200201
:list('disable_background', 'string', 'boolean')
201202
:one_of('style', { 'full', 'normal', 'language', 'none' })
202203
:one_of('position', { 'left', 'right' })

Diff for: lua/render-markdown/types.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,11 @@
164164
---@field border render.md.code.Border
165165
---@field above string
166166
---@field below string
167+
---@field inline_pad integer
167168
---@field highlight string
168169
---@field highlight_language? string
170+
---@field highlight_border string|boolean
169171
---@field highlight_fallback string
170-
---@field inline_pad integer
171172
---@field highlight_inline string
172173

173174
---@class (exact) render.md.Paragraph: render.md.BaseComponent

Diff for: tests/callout_spec.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('callout.md', function()
4343
:add(row:get(), row:get(), 2, 5, util.conceal())
4444
:add(row:get(), nil, 5, nil, util.code.icon('lua'))
4545
:add(row:get(), row:get(), 5, 8, util.conceal())
46-
:add(row:get(), row:inc(), 2, 0, util.code.bg())
46+
:add(row:get(), row:inc(), 2, 0, util.code.border('above'))
4747
:add(row:get(), row:get(), 0, 2, util.quote('%s ', ok))
4848
:add(row:get(), row:inc(), 2, 0, util.code.bg())
4949
:add(row:get(), row:get(), 0, 2, util.quote('%s ', ok))

Diff for: tests/code_spec.lua

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('code', function()
4343
:add(row:get(), row:get(), 0, 3, util.conceal())
4444
:add(row:get(), nil, 3, nil, util.code.icon('rust'))
4545
:add(row:get(), row:get(), 3, 7, util.conceal())
46-
:add(row:get(), row:inc(), 0, 0, util.code.bg())
46+
:add(row:get(), row:inc(), 0, 0, util.code.border('above'))
4747
:add(row:get(), row:inc(), 0, 0, util.code.bg())
4848
:add(row:get(), row:inc(), 0, 0, util.code.bg())
4949
:add(row:get(), row:inc(), 0, 0, util.code.bg())
@@ -57,7 +57,7 @@ describe('code', function()
5757
:add(row:get(), row:get(), 2, 5, util.conceal())
5858
:add(row:get(), nil, 5, nil, util.code.icon('py'))
5959
:add(row:get(), row:get(), 5, 7, util.conceal())
60-
:add(row:get(), row:inc(), 2, 0, util.code.bg())
60+
:add(row:get(), row:inc(), 2, 0, util.code.border('above'))
6161
:add(row:get(), row:inc(), 2, 0, util.code.bg())
6262
:add(row:get(), nil, 0, nil, util.padding(2, 1000))
6363
:add(row:get(), row:inc(), 0, 0, util.code.bg())
@@ -70,7 +70,7 @@ describe('code', function()
7070
:add(row:get(), row:get(), 0, 5, util.conceal())
7171
:add(row:get(), nil, 5, nil, util.code.icon('lua', 2))
7272
:add(row:get(), row:get(), 5, 8, util.conceal())
73-
:add(row:get(), row:inc(), 0, 0, util.code.bg())
73+
:add(row:get(), row:inc(), 0, 0, util.code.border('above'))
7474
:add(row:get(), row:inc(), 0, 0, util.code.bg())
7575
:add(row:get(), row:inc(), 0, 0, util.code.bg())
7676
:add(row:get(), row:inc(), 0, 0, util.code.bg())
@@ -126,7 +126,7 @@ describe('code', function()
126126
:add(row:get(), nil, 3, nil, util.code.icon('rust'))
127127
:add(row:get(), row:get(), 3, 7, util.conceal())
128128
:add(row:get(), nil, 0, nil, util.code.hide(width_1))
129-
:add(row:get(), row:inc(), 0, 0, util.code.bg())
129+
:add(row:get(), row:inc(), 0, 0, util.code.border('above'))
130130
:add(row:get(), nil, 0, nil, util.padding(2, 0, 'RmCode'))
131131
:add(row:get(), nil, 0, nil, util.code.hide(width_1))
132132
:add(row:get(), row:inc(), 0, 0, util.code.bg())
@@ -136,7 +136,7 @@ describe('code', function()
136136
:add(row:get(), nil, 0, nil, util.padding(2, 0, 'RmCode'))
137137
:add(row:get(), nil, 0, nil, util.code.hide(width_1))
138138
:add(row:get(), row:inc(), 0, 0, util.code.bg())
139-
:add(row:get(), nil, 0, nil, util.code.border(false, width_1))
139+
:add(row:get(), nil, 0, nil, util.code.border('below', width_1))
140140
:add(row:get(), row:get(), 0, 3, util.conceal())
141141

142142
marks:add(row:inc(2), row:get(), 0, 2, util.bullet(1))
@@ -148,7 +148,7 @@ describe('code', function()
148148
:add(row:get(), nil, 5, nil, util.code.icon('py'))
149149
:add(row:get(), row:get(), 5, 7, util.conceal())
150150
:add(row:get(), nil, 2, nil, util.code.hide(width_2))
151-
:add(row:get(), row:inc(), 2, 0, util.code.bg())
151+
:add(row:get(), row:inc(), 2, 0, util.code.border('above'))
152152
:add(row:get(), nil, 2, nil, util.padding(2, 1000, 'RmCode'))
153153
:add(row:get(), nil, 2, nil, util.code.hide(width_2))
154154
:add(row:get(), row:inc(), 2, 0, util.code.bg())
@@ -162,7 +162,7 @@ describe('code', function()
162162
:add(row:get(), nil, 2, nil, util.padding(2, 1000, 'RmCode'))
163163
:add(row:get(), nil, 2, nil, util.code.hide(width_2))
164164
:add(row:get(), row:inc(), 2, 0, util.code.bg())
165-
:add(row:get(), nil, 2, nil, util.code.border(false, width_2 - 2))
165+
:add(row:get(), nil, 2, nil, util.code.border('below', width_2 - 2))
166166
:add(row:get(), row:get(), 2, 5, util.conceal())
167167

168168
local width_3 = 20
@@ -172,7 +172,7 @@ describe('code', function()
172172
:add(row:get(), nil, 5, nil, util.code.icon('lua', 2))
173173
:add(row:get(), row:get(), 5, 8, util.conceal())
174174
:add(row:get(), nil, 0, nil, util.code.hide(width_3))
175-
:add(row:get(), row:inc(), 0, 0, util.code.bg())
175+
:add(row:get(), row:inc(), 0, 0, util.code.border('above'))
176176
:add(row:get(), nil, 0, nil, util.padding(2, 0, 'RmCode'))
177177
:add(row:get(), nil, 0, nil, util.code.hide(width_3))
178178
:add(row:get(), row:inc(), 0, 0, util.code.bg())
@@ -182,19 +182,19 @@ describe('code', function()
182182
:add(row:get(), nil, 0, nil, util.padding(2, 0, 'RmCode'))
183183
:add(row:get(), nil, 0, nil, util.code.hide(width_3))
184184
:add(row:get(), row:inc(), 0, 0, util.code.bg())
185-
:add(row:get(), nil, 0, nil, util.code.border(false, width_3))
185+
:add(row:get(), nil, 0, nil, util.code.border('below', width_3))
186186
:add(row:get(), row:get(), 0, 5, util.conceal())
187187

188188
marks:add(row:inc(2), row:get(), 0, 2, util.bullet(1))
189189

190190
local width_4 = (2 * vim.o.tabstop) + 24
191191
marks
192-
:add(row:inc(2), nil, 0, nil, util.code.border(true, width_4))
192+
:add(row:inc(2), nil, 0, nil, util.code.border('above', width_4))
193193
:add(row:get(), row:get(), 0, 3, util.conceal())
194194
:add(row:inc(), nil, 0, nil, util.padding(vim.o.tabstop, 0, 'RmCode'))
195195
:add(row:get(), nil, 0, nil, util.code.hide(width_4))
196196
:add(row:get(), row:inc(), 0, 0, util.code.bg())
197-
:add(row:get(), nil, 0, nil, util.code.border(false, width_4))
197+
:add(row:get(), nil, 0, nil, util.code.border('below', width_4))
198198
:add(row:get(), row:get(), 0, 3, util.conceal())
199199

200200
util.assert_view(marks, {

Diff for: tests/heading_code_spec.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ describe('heading_code.md', function()
4040
:add(row:get(), row:get(), 0, 3, util.conceal())
4141
:add(row:get(), nil, 3, nil, util.code.icon('python'))
4242
:add(row:get(), row:get(), 3, 9, util.conceal())
43-
for _ = 13, 22 do
43+
:add(row:get(), row:inc(), 0, 0, util.code.border('above'))
44+
for _ = 14, 22 do
4445
marks:add(row:get(), row:inc(), 0, 0, util.code.bg())
4546
end
4647
marks:add(row:get(), row:get(), 0, 3, util.conceal())

0 commit comments

Comments
 (0)