Skip to content

Commit a1b0988

Browse files
feat: allow checkbox to render bullet
## Details Request: #423 Adds `checkbox.bullet` option which defaults to `false`. When `false` the bullet point is hidden, maintaining the current behavior. When `true` we execute the bullet point render logic in addition to the checkbox render logic.
1 parent 935c2c7 commit a1b0988

File tree

8 files changed

+57
-36
lines changed

8 files changed

+57
-36
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,8 @@ require('render-markdown').setup({
563563
enabled = true,
564564
-- Additional modes to render checkboxes.
565565
render_modes = false,
566+
-- Render the bullet point before the checkbox.
567+
bullet = false,
566568
-- Padding to add to the right of checkboxes.
567569
right_pad = 1,
568570
unchecked = {
@@ -1203,6 +1205,8 @@ require('render-markdown').setup({
12031205
enabled = true,
12041206
-- Additional modes to render checkboxes.
12051207
render_modes = false,
1208+
-- Render the bullet point before the checkbox.
1209+
bullet = false,
12061210
-- Padding to add to the right of checkboxes.
12071211
right_pad = 1,
12081212
unchecked = {

doc/render-markdown.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 May 08
1+
*render-markdown.txt* For NVIM v0.11.1 Last change: 2025 May 12
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -628,6 +628,8 @@ Default Configuration ~
628628
enabled = true,
629629
-- Additional modes to render checkboxes.
630630
render_modes = false,
631+
-- Render the bullet point before the checkbox.
632+
bullet = false,
631633
-- Padding to add to the right of checkboxes.
632634
right_pad = 1,
633635
unchecked = {
@@ -1256,6 +1258,8 @@ Checkbox Configuration ~
12561258
enabled = true,
12571259
-- Additional modes to render checkboxes.
12581260
render_modes = false,
1261+
-- Render the bullet point before the checkbox.
1262+
bullet = false,
12591263
-- Padding to add to the right of checkboxes.
12601264
right_pad = 1,
12611265
unchecked = {

lua/render-markdown/config/checkbox.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
---@class (exact) render.md.checkbox.Config: render.md.base.Config
2+
---@field bullet boolean
23
---@field right_pad integer
34
---@field unchecked render.md.checkbox.component.Config
45
---@field checked render.md.checkbox.component.Config
@@ -27,6 +28,8 @@ M.default = {
2728
enabled = true,
2829
-- Additional modes to render checkboxes.
2930
render_modes = false,
31+
-- Render the bullet point before the checkbox.
32+
bullet = false,
3033
-- Padding to add to the right of checkboxes.
3134
right_pad = 1,
3235
unchecked = {
@@ -62,6 +65,7 @@ M.default = {
6265
function M.validate(spec)
6366
local Base = require('render-markdown.config.base')
6467
Base.validate(spec)
68+
spec:type('bullet', 'boolean')
6569
spec:type('right_pad', 'number')
6670
spec:nested({ 'unchecked', 'checked' }, function(box)
6771
box:type('icon', 'string')

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
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.4.0'
8+
M.version = '8.4.1'
99

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

lua/render-markdown/integ/source.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ function M.items(buf, row, col)
6262
if node:type() == 'block_quote' then
6363
for _, value in pairs(config.callout) do
6464
if filter.callout(value) then
65-
items[#items + 1] = M.item(prefix, value.raw, value.rendered)
65+
local detail = ' ' .. value.rendered
66+
items[#items + 1] = M.item(prefix, value.raw, detail)
6667
end
6768
end
6869
elseif node:type() == 'list_item' then
@@ -141,7 +142,8 @@ function M.item(prefix, label, detail, description)
141142
---@type lsp.CompletionItem
142143
return {
143144
kind = 12,
144-
label = prefix .. label,
145+
label = label,
146+
insertText = prefix .. label,
145147
labelDetails = {
146148
detail = detail,
147149
description = description,

lua/render-markdown/render/markdown/checkbox.lua

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local Base = require('render-markdown.render.base')
2+
local Bullet = require('render-markdown.render.markdown.bullet')
23
local Str = require('render-markdown.lib.str')
34

45
---@class render.md.checkbox.Data
@@ -65,10 +66,14 @@ end
6566

6667
---@private
6768
function Render:marker()
68-
-- https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
69-
local node = self.data.marker
70-
local offset = { 0, Str.spaces('start', node.text), 0, 0 }
71-
self.marks:over('check_icon', node, { conceal = '' }, offset)
69+
if self.config.bullet then
70+
Bullet:execute(self.context, self.marks, self.node)
71+
else
72+
-- https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
73+
local node = self.data.marker
74+
local offset = { 0, Str.spaces('start', node.text), 0, 0 }
75+
self.marks:over('check_icon', node, { conceal = '' }, offset)
76+
end
7277
end
7378

7479
---@private

lua/render-markdown/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
---@field category? string
6464

6565
---@class (exact) render.md.checkbox.UserConfig: render.md.base.UserConfig
66+
---@field bullet? boolean
6667
---@field right_pad? integer
6768
---@field unchecked? render.md.checkbox.component.UserConfig
6869
---@field checked? render.md.checkbox.component.UserConfig

tests/comp_spec.lua

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ local function item(prefix, label, detail, description)
2323
---@type lsp.CompletionItem
2424
return {
2525
kind = 12,
26-
label = prefix .. label,
26+
label = label,
27+
insertText = prefix .. label,
2728
labelDetails = {
2829
detail = detail,
2930
description = description,
@@ -102,33 +103,33 @@ describe('comp.md', function()
102103
---@return lsp.CompletionItem[]
103104
local function items(prefix)
104105
return {
105-
item(prefix, '[!ABSTRACT]', '󰨸 Abstract'),
106-
item(prefix, '[!ATTENTION]', '󰀪 Attention'),
107-
item(prefix, '[!BUG]', '󰨰 Bug'),
108-
item(prefix, '[!CAUTION]', '󰳦 Caution'),
109-
item(prefix, '[!CHECK]', '󰄬 Check'),
110-
item(prefix, '[!CITE]', '󱆨 Cite'),
111-
item(prefix, '[!DANGER]', '󱐌 Danger'),
112-
item(prefix, '[!DONE]', '󰄬 Done'),
113-
item(prefix, '[!ERROR]', '󱐌 Error'),
114-
item(prefix, '[!EXAMPLE]', '󰉹 Example'),
115-
item(prefix, '[!FAILURE]', '󰅖 Failure'),
116-
item(prefix, '[!FAIL]', '󰅖 Fail'),
117-
item(prefix, '[!FAQ]', '󰘥 Faq'),
118-
item(prefix, '[!HELP]', '󰘥 Help'),
119-
item(prefix, '[!HINT]', '󰌶 Hint'),
120-
item(prefix, '[!IMPORTANT]', '󰅾 Important'),
121-
item(prefix, '[!INFO]', '󰋽 Info'),
122-
item(prefix, '[!MISSING]', '󰅖 Missing'),
123-
item(prefix, '[!NOTE]', '󰋽 Note'),
124-
item(prefix, '[!QUESTION]', '󰘥 Question'),
125-
item(prefix, '[!QUOTE]', '󱆨 Quote'),
126-
item(prefix, '[!SUCCESS]', '󰄬 Success'),
127-
item(prefix, '[!SUMMARY]', '󰨸 Summary'),
128-
item(prefix, '[!TIP]', '󰌶 Tip'),
129-
item(prefix, '[!TLDR]', '󰨸 Tldr'),
130-
item(prefix, '[!TODO]', '󰗡 Todo'),
131-
item(prefix, '[!WARNING]', '󰀪 Warning'),
106+
item(prefix, '[!ABSTRACT]', ' 󰨸 Abstract'),
107+
item(prefix, '[!ATTENTION]', ' 󰀪 Attention'),
108+
item(prefix, '[!BUG]', ' 󰨰 Bug'),
109+
item(prefix, '[!CAUTION]', ' 󰳦 Caution'),
110+
item(prefix, '[!CHECK]', ' 󰄬 Check'),
111+
item(prefix, '[!CITE]', ' 󱆨 Cite'),
112+
item(prefix, '[!DANGER]', ' 󱐌 Danger'),
113+
item(prefix, '[!DONE]', ' 󰄬 Done'),
114+
item(prefix, '[!ERROR]', ' 󱐌 Error'),
115+
item(prefix, '[!EXAMPLE]', ' 󰉹 Example'),
116+
item(prefix, '[!FAILURE]', ' 󰅖 Failure'),
117+
item(prefix, '[!FAIL]', ' 󰅖 Fail'),
118+
item(prefix, '[!FAQ]', ' 󰘥 Faq'),
119+
item(prefix, '[!HELP]', ' 󰘥 Help'),
120+
item(prefix, '[!HINT]', ' 󰌶 Hint'),
121+
item(prefix, '[!IMPORTANT]', ' 󰅾 Important'),
122+
item(prefix, '[!INFO]', ' 󰋽 Info'),
123+
item(prefix, '[!MISSING]', ' 󰅖 Missing'),
124+
item(prefix, '[!NOTE]', ' 󰋽 Note'),
125+
item(prefix, '[!QUESTION]', ' 󰘥 Question'),
126+
item(prefix, '[!QUOTE]', ' 󱆨 Quote'),
127+
item(prefix, '[!SUCCESS]', ' 󰄬 Success'),
128+
item(prefix, '[!SUMMARY]', ' 󰨸 Summary'),
129+
item(prefix, '[!TIP]', ' 󰌶 Tip'),
130+
item(prefix, '[!TLDR]', ' 󰨸 Tldr'),
131+
item(prefix, '[!TODO]', ' 󰗡 Todo'),
132+
item(prefix, '[!WARNING]', ' 󰀪 Warning'),
132133
}
133134
end
134135

0 commit comments

Comments
 (0)