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

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
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

README.md

Lines changed: 9 additions & 2 deletions
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 = {},

doc/render-markdown.txt

Lines changed: 9 additions & 2 deletions
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 = {},

lua/render-markdown/handler/markdown.lua

Lines changed: 2 additions & 2 deletions
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

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
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')

lua/render-markdown/init.lua

Lines changed: 13 additions & 2 deletions
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 = {},

lua/render-markdown/render/base.lua

Lines changed: 1 addition & 1 deletion
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

lua/render-markdown/render/code.lua

Lines changed: 5 additions & 4 deletions
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 = {}

lua/render-markdown/render/heading.lua

Lines changed: 2 additions & 2 deletions
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

lua/render-markdown/render/section.lua

Lines changed: 1 addition & 1 deletion
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

0 commit comments

Comments
 (0)