Skip to content

Commit 095078d

Browse files
feat: make padding highlight configurable
## Details Issue: #176 Currently all the padding added by this plugin is hard coded to the highlight group `Normal`. This is by convention the value used for backgrounds which allows us to create empty space. However in floating windows like LSP hover docs the background uses the `NormalFloat` highlight instead. To fix this add a new top level configuration for `padding` with a single key for `highlight`. This by default is set to `Normal`. Updates the default override for `nofile` to use the `NormalFloat` value instead which should fix any background color issues with LSP hover docs.
1 parent c686970 commit 095078d

File tree

13 files changed

+63
-18
lines changed

13 files changed

+63
-18
lines changed

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22

33
## Pre-release
44

5+
### Features
6+
7+
- `pipe_table.cell` value `trimmed` [#175](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/175)
8+
[c686970](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c68697085441d03a20eee15d4d78e2e5a771569a)
9+
510
## 7.1.0 (2024-09-19)
611

712
### Features

Diff for: README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,10 @@ require('render-markdown').setup({
218218
-- Number of lines below cursor to show
219219
below = 0,
220220
},
221+
padding = {
222+
-- Highlight to use when adding whitespace, should match background
223+
highlight = 'Normal',
224+
},
221225
latex = {
222226
-- Whether LaTeX should be rendered, mainly used for health check
223227
enabled = true,
@@ -541,12 +545,15 @@ require('render-markdown').setup({
541545
-- More granular configuration mechanism, allows different aspects of buffers
542546
-- to have their own behavior. Values default to the top level configuration
543547
-- if no override is provided. Supports the following fields:
544-
-- enabled, max_file_size, debounce, render_modes, anti_conceal, heading, code,
548+
-- enabled, max_file_size, debounce, render_modes, anti_conceal, padding, heading, code,
545549
-- dash, bullet, checkbox, quote, pipe_table, callout, link, sign, indent, win_options
546550
overrides = {
547551
-- Overrides for different buftypes, see :h 'buftype'
548552
buftype = {
549-
nofile = { sign = { enabled = false } },
553+
nofile = {
554+
padding = { highlight = 'NormalFloat' },
555+
sign = { enabled = false },
556+
},
550557
},
551558
-- Overrides for different filetypes, see :h 'filetype'
552559
filetype = {},

Diff for: doc/render-markdown.txt

+9-2
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ Full Default Configuration ~
264264
-- Number of lines below cursor to show
265265
below = 0,
266266
},
267+
padding = {
268+
-- Highlight to use when adding whitespace, should match background
269+
highlight = 'Normal',
270+
},
267271
latex = {
268272
-- Whether LaTeX should be rendered, mainly used for health check
269273
enabled = true,
@@ -587,12 +591,15 @@ Full Default Configuration ~
587591
-- More granular configuration mechanism, allows different aspects of buffers
588592
-- to have their own behavior. Values default to the top level configuration
589593
-- if no override is provided. Supports the following fields:
590-
-- enabled, max_file_size, debounce, render_modes, anti_conceal, heading, code,
594+
-- enabled, max_file_size, debounce, render_modes, anti_conceal, padding, heading, code,
591595
-- dash, bullet, checkbox, quote, pipe_table, callout, link, sign, indent, win_options
592596
overrides = {
593597
-- Overrides for different buftypes, see :h 'buftype'
594598
buftype = {
595-
nofile = { sign = { enabled = false } },
599+
nofile = {
600+
padding = { highlight = 'NormalFloat' },
601+
sign = { enabled = false },
602+
},
596603
},
597604
-- Overrides for different filetypes, see :h 'filetype'
598605
filetype = {},

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,13 @@ function Handler:list_marker(info)
122122
if bullet.left_pad > 0 then
123123
self.marks:add(false, info.start_row, 0, {
124124
priority = 0,
125-
virt_text = { { str.pad(bullet.left_pad), 'Normal' } },
125+
virt_text = { { str.pad(bullet.left_pad), self.config.padding.highlight } },
126126
virt_text_pos = 'inline',
127127
})
128128
end
129129
if bullet.right_pad > 0 then
130130
self.marks:add(true, info.start_row, info.end_col - 1, {
131-
virt_text = { { str.pad(bullet.right_pad), 'Normal' } },
131+
virt_text = { { str.pad(bullet.right_pad), self.config.padding.highlight } },
132132
virt_text_pos = 'inline',
133133
})
134134
end

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

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

66
---@private
7-
M.version = '7.1.2'
7+
M.version = '7.1.3'
88

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

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

+13-2
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ local M = {}
144144
---@field public backgrounds? string[]
145145
---@field public foregrounds? string[]
146146

147+
---@class (exact) render.md.UserPadding
148+
---@field public highlight? string
149+
147150
---@class (exact) render.md.UserAntiConceal
148151
---@field public enabled? boolean
149152
---@field public above? integer
@@ -159,6 +162,7 @@ local M = {}
159162
---@field public debounce? integer
160163
---@field public render_modes? string[]|boolean
161164
---@field public anti_conceal? render.md.UserAntiConceal
165+
---@field public padding? render.md.UserPadding
162166
---@field public heading? render.md.UserHeading
163167
---@field public code? render.md.UserCode
164168
---@field public dash? render.md.UserDash
@@ -285,6 +289,10 @@ M.default_config = {
285289
-- Number of lines below cursor to show
286290
below = 0,
287291
},
292+
padding = {
293+
-- Highlight to use when adding whitespace, should match background
294+
highlight = 'Normal',
295+
},
288296
latex = {
289297
-- Whether LaTeX should be rendered, mainly used for health check
290298
enabled = true,
@@ -608,12 +616,15 @@ M.default_config = {
608616
-- More granular configuration mechanism, allows different aspects of buffers
609617
-- to have their own behavior. Values default to the top level configuration
610618
-- if no override is provided. Supports the following fields:
611-
-- enabled, max_file_size, debounce, render_modes, anti_conceal, heading, code,
619+
-- enabled, max_file_size, debounce, render_modes, anti_conceal, padding, heading, code,
612620
-- dash, bullet, checkbox, quote, pipe_table, callout, link, sign, indent, win_options
613621
overrides = {
614622
-- Overrides for different buftypes, see :h 'buftype'
615623
buftype = {
616-
nofile = { sign = { enabled = false } },
624+
nofile = {
625+
padding = { highlight = 'NormalFloat' },
626+
sign = { enabled = false },
627+
},
617628
},
618629
-- Overrides for different filetypes, see :h 'filetype'
619630
filetype = {},

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
function Base:indent_virt_line(line, level)
4747
local amount = self:indent(level)
4848
if amount > 0 then
49-
table.insert(line, 1, { str.pad(amount), 'Normal' })
49+
table.insert(line, 1, { str.pad(amount), self.config.padding.highlight })
5050
end
5151
return line
5252
end

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ function Render:background(icon_added)
163163
hl_eol = true,
164164
})
165165
if self.code.width == 'block' then
166-
-- Overwrite anything beyond width with Normal
166+
-- Overwrite anything beyond width with padding highlight
167167
self.marks:add(false, row, self.data.col, {
168168
priority = 0,
169-
virt_text = { { padding, 'Normal' } },
169+
virt_text = { { padding, self.config.padding.highlight } },
170170
virt_text_win_col = width + self.data.indent,
171171
})
172172
end
@@ -189,8 +189,9 @@ function Render:left_pad(add_background)
189189

190190
-- Use low priority to include other marks in padding when code block is at edge
191191
local priority = self.data.col == 0 and 0 or nil
192-
local outer_text = { str.pad(self.data.col), 'Normal' }
193-
local left_text = { str.pad(self.code.left_pad), add_background and self.code.highlight or 'Normal' }
192+
local outer_text = { str.pad(self.data.col), self.config.padding.highlight }
193+
local background = add_background and self.code.highlight or self.config.padding.highlight
194+
local left_text = { str.pad(self.code.left_pad), background }
194195

195196
for row = self.data.start_row, self.data.end_row - 1 do
196197
local virt_text = {}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ function Render:background(width)
149149
hl_eol = true,
150150
})
151151
if self.data.heading_width == 'block' then
152-
-- Overwrite anything beyond width with Normal
152+
-- Overwrite anything beyond width with padding highlight
153153
self.marks:add(true, row, 0, {
154154
priority = 0,
155-
virt_text = { { str.pad(vim.o.columns * 2), 'Normal' } },
155+
virt_text = { { str.pad(vim.o.columns * 2), self.config.padding.highlight } },
156156
virt_text_win_col = win_col,
157157
})
158158
end

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function Render:render()
6464
for row = start_row, end_row do
6565
self.marks:add(false, row, 0, {
6666
priority = 0,
67-
virt_text = { { str.pad(self.indent.per_level * self.level_change), 'Normal' } },
67+
virt_text = { { str.pad(self.indent.per_level * self.level_change), self.config.padding.highlight } },
6868
virt_text_pos = 'inline',
6969
})
7070
end

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ function Render:full()
325325
---@param above boolean
326326
---@param chars { [1]: string, [2]: string, [3]: string }
327327
local function table_border(info, above, chars)
328-
local line = spaces > 0 and { { str.pad(spaces), 'Normal' } } or {}
328+
local line = spaces > 0 and { { str.pad(spaces), self.config.padding.highlight } } or {}
329329
local highlight = above and self.table.head or self.table.row
330330
table.insert(line, { chars[1] .. table.concat(sections, chars[2]) .. chars[3], highlight })
331331
self.marks:add(false, info.start_row, info.start_col, {

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

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ function M.default_buffer_config()
9595
debounce = config.debounce,
9696
render_modes = config.render_modes,
9797
anti_conceal = config.anti_conceal,
98+
padding = config.padding,
9899
heading = config.heading,
99100
code = config.code,
100101
dash = config.dash,
@@ -225,6 +226,13 @@ function M.validate()
225226
})
226227
end
227228

229+
local padding = config.padding
230+
if padding ~= nil then
231+
append_errors(path .. '.padding', padding, {
232+
highlight = { padding.highlight, 'string', nilable },
233+
})
234+
end
235+
228236
local heading = config.heading
229237
if heading ~= nil then
230238
append_errors(path .. '.heading', heading, {
@@ -414,6 +422,7 @@ function M.validate()
414422
debounce = { config.debounce, 'number' },
415423
render_modes = string_array(config.render_modes, { 'boolean' }, false),
416424
anti_conceal = { config.anti_conceal, 'table' },
425+
padding = { config.padding, 'table' },
417426
heading = { config.heading, 'table' },
418427
code = { config.code, 'table' },
419428
dash = { config.dash, 'table' },
@@ -471,6 +480,7 @@ function M.validate()
471480
debounce = { override.debounce, 'number', true },
472481
render_modes = string_array(override.render_modes, {}, true),
473482
anti_conceal = { override.anti_conceal, 'table', true },
483+
padding = { override.padding, 'table', true },
474484
heading = { override.heading, 'table', true },
475485
code = { override.code, 'table', true },
476486
dash = { override.dash, 'table', true },

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

+4
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@
119119
---@field public backgrounds string[]
120120
---@field public foregrounds string[]
121121

122+
---@class (exact) render.md.Padding
123+
---@field public highlight string
124+
122125
---@class (exact) render.md.AntiConceal
123126
---@field public enabled boolean
124127
---@field public above integer
@@ -134,6 +137,7 @@
134137
---@field public debounce integer
135138
---@field public render_modes string[]|boolean
136139
---@field public anti_conceal render.md.AntiConceal
140+
---@field public padding render.md.Padding
137141
---@field public heading render.md.Heading
138142
---@field public code render.md.Code
139143
---@field public dash render.md.Dash

0 commit comments

Comments
 (0)