Skip to content

Commit 2c8be07

Browse files
feat: Add bullet.right_pad option
1 parent 56d92af commit 2c8be07

File tree

6 files changed

+37
-6
lines changed

6 files changed

+37
-6
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ require('render-markdown').setup({
267267
-- The 'level' is used to index into the array using a cycle
268268
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
269269
icons = { '', '', '', '' },
270+
-- Padding to add to the right of bullet point
271+
right_pad = 0,
270272
-- Highlight for the bullet icon
271273
highlight = 'RenderMarkdownBullet',
272274
},
@@ -519,6 +521,8 @@ require('render-markdown').setup({
519521
-- The 'level' is used to index into the array using a cycle
520522
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
521523
icons = { '', '', '', '' },
524+
-- Padding to add to the right of bullet point
525+
right_pad = 0,
522526
-- Highlight for the bullet icon
523527
highlight = 'RenderMarkdownBullet',
524528
},

doc/render-markdown.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,8 @@ Full Default Configuration ~
307307
-- The 'level' is used to index into the array using a cycle
308308
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
309309
icons = { '●', '○', '◆', '◇' },
310+
-- Padding to add to the right of bullet point
311+
right_pad = 0,
310312
-- Highlight for the bullet icon
311313
highlight = 'RenderMarkdownBullet',
312314
},
@@ -561,6 +563,8 @@ LIST BULLETS *render-markdown-setup-list-bullets*
561563
-- The 'level' is used to index into the array using a cycle
562564
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
563565
icons = { '●', '○', '◆', '◇' },
566+
-- Padding to add to the right of bullet point
567+
right_pad = 0,
564568
-- Highlight for the bullet icon
565569
highlight = 'RenderMarkdownBullet',
566570
},

lua/render-markdown/handler/markdown.lua

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ M.parse = function(root, buf)
2929
elseif capture == 'code' then
3030
vim.list_extend(marks, M.render_code(buf, info))
3131
elseif capture == 'list_marker' then
32-
list.add(marks, M.render_list_marker(buf, info))
32+
vim.list_extend(marks, M.render_list_marker(buf, info))
3333
elseif capture == 'checkbox_unchecked' then
3434
list.add(marks, M.render_checkbox(info, state.config.checkbox.unchecked))
3535
elseif capture == 'checkbox_checked' then
@@ -335,7 +335,7 @@ end
335335
---@private
336336
---@param buf integer
337337
---@param info render.md.NodeInfo
338-
---@return render.md.Mark?
338+
---@return render.md.Mark[]
339339
M.render_list_marker = function(buf, info)
340340
---@return boolean
341341
local function sibling_checkbox()
@@ -357,7 +357,7 @@ M.render_list_marker = function(buf, info)
357357
if sibling_checkbox() then
358358
-- Hide the list marker for checkboxes rather than replacing with a bullet point
359359
---@type render.md.Mark
360-
return {
360+
local checkbox_mark = {
361361
conceal = true,
362362
start_row = info.start_row,
363363
start_col = info.start_col,
@@ -367,22 +367,24 @@ M.render_list_marker = function(buf, info)
367367
conceal = '',
368368
},
369369
}
370+
return { checkbox_mark }
370371
else
371372
local bullet = state.config.bullet
372373
if not bullet.enabled then
373-
return nil
374+
return {}
374375
end
375376
local level = ts.level_in_section(info, 'list')
376377
local icon = list.cycle(bullet.icons, level)
377378
if icon == nil then
378-
return nil
379+
return {}
379380
end
381+
local marks = {}
380382
-- List markers from tree-sitter should have leading spaces removed, however there are known
381383
-- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
382384
-- As a result we handle leading spaces here, can remove if this gets fixed upstream
383385
local leading_spaces = str.leading_spaces(info.text)
384386
---@type render.md.Mark
385-
return {
387+
local bullet_mark = {
386388
conceal = true,
387389
start_row = info.start_row,
388390
start_col = info.start_col,
@@ -393,6 +395,22 @@ M.render_list_marker = function(buf, info)
393395
virt_text_pos = 'overlay',
394396
},
395397
}
398+
list.add(marks, bullet_mark)
399+
-- Requires inline extmarks
400+
if util.has_10 and bullet.right_pad > 0 then
401+
---@type render.md.Mark
402+
local padding_mark = {
403+
conceal = true,
404+
start_row = info.start_row,
405+
start_col = info.end_col - 1,
406+
opts = {
407+
virt_text = { { str.pad('', bullet.right_pad), 'Normal' } },
408+
virt_text_pos = 'inline',
409+
},
410+
}
411+
list.add(marks, padding_mark)
412+
end
413+
return marks
396414
end
397415
end
398416

lua/render-markdown/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ local M = {}
6262
---@class render.md.UserBullet
6363
---@field public enabled? boolean
6464
---@field public icons? string[]
65+
---@field public right_pad? integer
6566
---@field public highlight? string
6667

6768
---@class render.md.UserDash
@@ -289,6 +290,8 @@ M.default_config = {
289290
-- The 'level' is used to index into the array using a cycle
290291
-- If the item is a 'checkbox' a conceal is used to hide the bullet instead
291292
icons = { '', '', '', '' },
293+
-- Padding to add to the right of bullet point
294+
right_pad = 0,
292295
-- Highlight for the bullet icon
293296
highlight = 'RenderMarkdownBullet',
294297
},

lua/render-markdown/state.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ function state.validate()
155155
append_errors('render-markdown.bullet', bullet, {
156156
enabled = { bullet.enabled, 'boolean' },
157157
icons = string_array(bullet.icons),
158+
right_pad = { bullet.right_pad, 'number' },
158159
highlight = { bullet.highlight, 'string' },
159160
})
160161

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
---@class render.md.Bullet
4848
---@field public enabled boolean
4949
---@field public icons string[]
50+
---@field public right_pad integer
5051
---@field public highlight string
5152

5253
---@class render.md.Dash

0 commit comments

Comments
 (0)