Skip to content

Commit e455c4f

Browse files
feat: left_pad list bullet point property
Adds `bullet -> left_pad` property which adds left padding to bullet points. Update how we do neovim version check to be inside of handler add methods. That way the logic more clearly reads like do not add inline marks if version is not at least 0.10.0. Is also a generally more safe approach as I do not need to remember to add it everytime I use inline marks.
1 parent 4b80b4f commit e455c4f

File tree

8 files changed

+54
-35
lines changed

8 files changed

+54
-35
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,8 @@ require('render-markdown').setup({
303303
-- The 'level' is used to index into the array using a cycle
304304
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
305305
icons = { '', '', '', '' },
306+
-- Padding to add to the left of bullet point
307+
left_pad = 0,
306308
-- Padding to add to the right of bullet point
307309
right_pad = 0,
308310
-- Highlight for the bullet icon
@@ -603,6 +605,8 @@ require('render-markdown').setup({
603605
-- The 'level' is used to index into the array using a cycle
604606
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
605607
icons = { '', '', '', '' },
608+
-- Padding to add to the left of bullet point
609+
left_pad = 0,
606610
-- Padding to add to the right of bullet point
607611
right_pad = 0,
608612
-- Highlight for the bullet icon

doc/render-markdown.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ Full Default Configuration ~
335335
-- The 'level' is used to index into the array using a cycle
336336
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
337337
icons = { '●', '○', '◆', '◇' },
338+
-- Padding to add to the left of bullet point
339+
left_pad = 0,
338340
-- Padding to add to the right of bullet point
339341
right_pad = 0,
340342
-- Highlight for the bullet icon
@@ -637,6 +639,8 @@ LIST BULLETS *render-markdown-setup-list-bullets*
637639
-- The 'level' is used to index into the array using a cycle
638640
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
639641
icons = { '●', '○', '◆', '◇' },
642+
-- Padding to add to the left of bullet point
643+
left_pad = 0,
640644
-- Padding to add to the right of bullet point
641645
right_pad = 0,
642646
-- Highlight for the bullet icon

lua/render-markdown/handler/markdown.lua

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,12 @@ end
7070
---@param start_row integer
7171
---@param start_col integer
7272
---@param opts vim.api.keyset.set_extmark
73+
---@return boolean
7374
function Handler:add(conceal, start_row, start_col, opts)
75+
-- Inline extmarks require neovim >= 0.10.0
76+
if opts.virt_text_pos == 'inline' and not util.has_10 then
77+
return false
78+
end
7479
---@type render.md.Mark
7580
local mark = {
7681
conceal = conceal,
@@ -80,6 +85,7 @@ function Handler:add(conceal, start_row, start_col, opts)
8085
}
8186
logger.debug('mark', mark)
8287
table.insert(self.marks, mark)
88+
return true
8389
end
8490

8591
---@private
@@ -114,16 +120,13 @@ function Handler:heading(info)
114120
-- and concealed text is subtracted since that space is not usable
115121
local padding = level + 1 - ts.concealed(self.buf, info) - str.width(icon)
116122
if heading.position == 'inline' or padding < 0 then
117-
-- Requires inline extmarks to place when there is not enough space available
118-
if util.has_10 then
119-
self:add(true, info.start_row, info.start_col, {
120-
end_row = info.end_row,
121-
end_col = info.end_col,
122-
virt_text = { { icon, { foreground, background } } },
123-
virt_text_pos = 'inline',
124-
conceal = '',
125-
})
126-
end
123+
self:add(true, info.start_row, info.start_col, {
124+
end_row = info.end_row,
125+
end_col = info.end_col,
126+
virt_text = { { icon, { foreground, background } } },
127+
virt_text_pos = 'inline',
128+
conceal = '',
129+
})
127130
else
128131
self:add(true, info.start_row, info.start_col, {
129132
end_row = info.end_row,
@@ -202,31 +205,28 @@ function Handler:language(code_block, add_background)
202205
if add_background then
203206
table.insert(highlight, code.highlight)
204207
end
205-
-- Requires inline extmarks
206-
if code.position == 'left' and util.has_10 then
208+
if code.position == 'left' then
207209
local icon_text = icon .. ' '
208210
if ts.hidden(self.buf, info) then
209211
-- Code blocks will pick up varying amounts of leading white space depending on the
210212
-- context they are in. This gets lumped into the delimiter node and as a result,
211213
-- after concealing, the extmark will be left shifted. Logic below accounts for this.
212214
icon_text = str.pad(code_block.leading_spaces, icon_text .. info.text)
213215
end
214-
self:add(true, info.start_row, info.start_col, {
216+
return self:add(true, info.start_row, info.start_col, {
215217
virt_text = { { icon_text, highlight } },
216218
virt_text_pos = 'inline',
217219
})
218-
return true
219220
elseif code.position == 'right' then
220221
local icon_text = icon .. ' ' .. info.text
221222
local win_col = code_block.longest_line
222223
if code.width == 'block' then
223224
win_col = win_col - str.width(icon_text)
224225
end
225-
self:add(true, info.start_row, 0, {
226+
return self:add(true, info.start_row, 0, {
226227
virt_text = { { icon_text, highlight } },
227228
virt_text_win_col = win_col,
228229
})
229-
return true
230230
else
231231
return false
232232
end
@@ -285,8 +285,7 @@ end
285285
---@param add_background boolean
286286
function Handler:code_left_pad(code_block, add_background)
287287
local code = self.config.code
288-
-- Requires inline extmarks
289-
if not util.has_10 or code.left_pad <= 0 then
288+
if code.left_pad <= 0 then
290289
return
291290
end
292291
local padding = str.pad(code.left_pad)
@@ -354,8 +353,14 @@ function Handler:list_marker(info)
354353
virt_text = { { str.pad(leading_spaces, icon), bullet.highlight } },
355354
virt_text_pos = 'overlay',
356355
})
357-
-- Requires inline extmarks
358-
if util.has_10 and bullet.right_pad > 0 then
356+
if bullet.left_pad > 0 then
357+
self:add(false, info.start_row, 0, {
358+
priority = 0,
359+
virt_text = { { str.pad(bullet.left_pad), 'Normal' } },
360+
virt_text_pos = 'inline',
361+
})
362+
end
363+
if bullet.right_pad > 0 then
359364
self:add(true, info.start_row, info.end_col - 1, {
360365
virt_text = { { str.pad(bullet.right_pad), 'Normal' } },
361366
virt_text_pos = 'inline',
@@ -495,8 +500,7 @@ function Handler:table_row(row, highlight)
495500
virt_text_pos = 'overlay',
496501
})
497502
elseif cell.type == 'pipe_table_cell' then
498-
-- Requires inline extmarks
499-
if pipe_table.cell == 'padded' and util.has_10 then
503+
if pipe_table.cell == 'padded' then
500504
local offset = self:table_visual_offset(cell)
501505
if offset > 0 then
502506
self:add(true, cell.start_row, cell.end_col - 1, {

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,12 @@ end
4646
---@param start_row integer
4747
---@param start_col integer
4848
---@param opts vim.api.keyset.set_extmark
49+
---@return boolean
4950
function Handler:add(start_row, start_col, opts)
51+
-- Inline extmarks require neovim >= 0.10.0
52+
if opts.virt_text_pos == 'inline' and not util.has_10 then
53+
return false
54+
end
5055
---@type render.md.Mark
5156
local mark = {
5257
conceal = true,
@@ -56,16 +61,14 @@ function Handler:add(start_row, start_col, opts)
5661
}
5762
logger.debug('mark', mark)
5863
table.insert(self.marks, mark)
64+
return true
5965
end
6066

6167
---@private
6268
---@param info render.md.NodeInfo
6369
function Handler:code(info)
6470
local code = self.config.code
65-
if not code.enabled then
66-
return
67-
end
68-
if not vim.tbl_contains({ 'normal', 'full' }, code.style) then
71+
if not code.enabled or not vim.tbl_contains({ 'normal', 'full' }, code.style) then
6972
return
7073
end
7174
self:add(info.start_row, info.start_col, {
@@ -130,8 +133,7 @@ end
130133
---@param info render.md.NodeInfo
131134
---@param checkbox render.md.CustomComponent
132135
function Handler:checkbox(info, checkbox)
133-
-- Requires inline extmarks
134-
if not self.config.checkbox.enabled or not util.has_10 then
136+
if not self.config.checkbox.enabled then
135137
return
136138
end
137139
self:add(info.start_row, info.start_col, {
@@ -146,8 +148,7 @@ end
146148
---@private
147149
---@param info render.md.NodeInfo
148150
function Handler:wiki_link(info)
149-
-- Requires inline extmarks
150-
if not self.config.link.enabled or not util.has_10 then
151+
if not self.config.link.enabled then
151152
return
152153
end
153154
local text = info.text:sub(2, -2)
@@ -165,18 +166,19 @@ end
165166
---@private
166167
---@param info render.md.NodeInfo
167168
function Handler:link(info)
168-
-- Requires inline extmarks
169-
if not self.config.link.enabled or not util.has_10 then
169+
if not self.config.link.enabled then
170170
return
171171
end
172172
local icon, highlight = self:link_virt_text(info)
173-
context.get(self.buf):add_link(info, icon)
174-
self:add(info.start_row, info.start_col, {
173+
local added = self:add(info.start_row, info.start_col, {
175174
end_row = info.end_row,
176175
end_col = info.end_col,
177176
virt_text = { { icon, highlight } },
178177
virt_text_pos = 'inline',
179178
})
179+
if added then
180+
context.get(self.buf):add_link(info, icon)
181+
end
180182
end
181183

182184
---@private

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local M = {}
55

66
---@private
77
---@type string
8-
M.version = '6.0.1'
8+
M.version = '6.0.2'
99

1010
function M.check()
1111
vim.health.start('render-markdown.nvim [version]')

lua/render-markdown/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ local M = {}
7272
---@class (exact) render.md.UserBullet
7373
---@field public enabled? boolean
7474
---@field public icons? string[]
75+
---@field public left_pad? integer
7576
---@field public right_pad? integer
7677
---@field public highlight? string
7778

@@ -326,6 +327,8 @@ M.default_config = {
326327
-- The 'level' is used to index into the array using a cycle
327328
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
328329
icons = { '', '', '', '' },
330+
-- Padding to add to the left of bullet point
331+
left_pad = 0,
329332
-- Padding to add to the right of bullet point
330333
right_pad = 0,
331334
-- Highlight for the bullet icon

lua/render-markdown/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ function M.validate()
208208
append_errors(path .. '.bullet', bullet, {
209209
enabled = { bullet.enabled, 'boolean', nilable },
210210
icons = string_array(bullet.icons, nilable),
211+
left_pad = { bullet.left_pad, 'number', nilable },
211212
right_pad = { bullet.right_pad, 'number', nilable },
212213
highlight = { bullet.highlight, 'string', nilable },
213214
})

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
---@class (exact) render.md.Bullet
6262
---@field public enabled boolean
6363
---@field public icons string[]
64+
---@field public left_pad integer
6465
---@field public right_pad integer
6566
---@field public highlight string
6667

0 commit comments

Comments
 (0)