Skip to content

Commit cb90caf

Browse files
feat: allow checked / unchecked chechbox to provide scope highlight
## Details Adds a `scope_highlight` property for use with checked and unchecked checkboxes. When provided the text associated with the checkbox gets highlighted by this value. This can be used to apply a strikethrough for checked checkboxes as an example.
1 parent cfb8bdd commit cb90caf

File tree

8 files changed

+67
-15
lines changed

8 files changed

+67
-15
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,16 @@ require('render-markdown').setup({
402402
icon = '󰄱 ',
403403
-- Highlight for the unchecked icon
404404
highlight = 'RenderMarkdownUnchecked',
405+
-- Highlight for item associated with unchecked checkbox
406+
scope_highlight = nil,
405407
},
406408
checked = {
407409
-- Replaces '[x]' of 'task_list_marker_checked'
408410
icon = '󰱒 ',
409411
-- Highligh for the checked icon
410412
highlight = 'RenderMarkdownChecked',
413+
-- Highlight for item associated with checked checkbox
414+
scope_highlight = nil,
411415
},
412416
-- Define custom checkbox states, more involved as they are not part of the markdown grammar
413417
-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks
@@ -830,12 +834,16 @@ require('render-markdown').setup({
830834
icon = '󰄱 ',
831835
-- Highlight for the unchecked icon
832836
highlight = 'RenderMarkdownUnchecked',
837+
-- Highlight for item associated with unchecked checkbox
838+
scope_highlight = nil,
833839
},
834840
checked = {
835841
-- Replaces '[x]' of 'task_list_marker_checked'
836842
icon = '󰱒 ',
837843
-- Highligh for the checked icon
838844
highlight = 'RenderMarkdownChecked',
845+
-- Highlight for item associated with checked checkbox
846+
scope_highlight = nil,
839847
},
840848
-- Define custom checkbox states, more involved as they are not part of the markdown grammar
841849
-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks

doc/render-markdown.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.10.0 Last change: 2024 September 29
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 September 30
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -450,12 +450,16 @@ Default Configuration ~
450450
icon = '󰄱 ',
451451
-- Highlight for the unchecked icon
452452
highlight = 'RenderMarkdownUnchecked',
453+
-- Highlight for item associated with unchecked checkbox
454+
scope_highlight = nil,
453455
},
454456
checked = {
455457
-- Replaces '[x]' of 'task_list_marker_checked'
456458
icon = '󰱒 ',
457459
-- Highligh for the checked icon
458460
highlight = 'RenderMarkdownChecked',
461+
-- Highlight for item associated with checked checkbox
462+
scope_highlight = nil,
459463
},
460464
-- Define custom checkbox states, more involved as they are not part of the markdown grammar
461465
-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks
@@ -868,12 +872,16 @@ Checkbox Configuration ~
868872
icon = '󰄱 ',
869873
-- Highlight for the unchecked icon
870874
highlight = 'RenderMarkdownUnchecked',
875+
-- Highlight for item associated with unchecked checkbox
876+
scope_highlight = nil,
871877
},
872878
checked = {
873879
-- Replaces '[x]' of 'task_list_marker_checked'
874880
icon = '󰱒 ',
875881
-- Highligh for the checked icon
876882
highlight = 'RenderMarkdownChecked',
883+
-- Highlight for item associated with checked checkbox
884+
scope_highlight = nil,
877885
},
878886
-- Define custom checkbox states, more involved as they are not part of the markdown grammar
879887
-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks

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.2.4'
7+
M.version = '7.2.5'
88

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

lua/render-markdown/init.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,21 @@ local M = {}
6767
---@field public row? string
6868
---@field public filler? string
6969

70-
---@class (exact) render.md.UserCustomComponent
71-
---@field public raw? string
72-
---@field public rendered? string
73-
---@field public highlight? string
74-
7570
---@class (exact) render.md.UserQuote
7671
---@field public enabled? boolean
7772
---@field public icon? string
7873
---@field public repeat_linebreak? boolean
7974
---@field public highlight? string
8075

76+
---@class (exact) render.md.UserCustomComponent
77+
---@field public raw? string
78+
---@field public rendered? string
79+
---@field public highlight? string
80+
8181
---@class (exact) render.md.UserCheckboxComponent
8282
---@field public icon? string
8383
---@field public highlight? string
84+
---@field public scope_highlight? string
8485

8586
---@alias render.md.checkbox.Position 'overlay'|'inline'
8687

@@ -89,7 +90,7 @@ local M = {}
8990
---@field public position? render.md.checkbox.Position
9091
---@field public unchecked? render.md.UserCheckboxComponent
9192
---@field public checked? render.md.UserCheckboxComponent
92-
---@field public custom? table<string, render.md.CustomComponent>
93+
---@field public custom? table<string, render.md.UserCustomComponent>
9394

9495
---@class (exact) render.md.UserBullet
9596
---@field public enabled? boolean
@@ -476,12 +477,16 @@ M.default_config = {
476477
icon = '󰄱 ',
477478
-- Highlight for the unchecked icon
478479
highlight = 'RenderMarkdownUnchecked',
480+
-- Highlight for item associated with unchecked checkbox
481+
scope_highlight = nil,
479482
},
480483
checked = {
481484
-- Replaces '[x]' of 'task_list_marker_checked'
482485
icon = '󰱒 ',
483486
-- Highligh for the checked icon
484487
highlight = 'RenderMarkdownChecked',
488+
-- Highlight for item associated with checked checkbox
489+
scope_highlight = nil,
485490
},
486491
-- Define custom checkbox states, more involved as they are not part of the markdown grammar
487492
-- As a result this requires neovim >= 0.10.0 since it relies on 'inline' extmarks

lua/render-markdown/render/checkbox.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ function Render:setup()
3838
end
3939

4040
function Render:render()
41+
self:icon()
42+
self:highlight_scope()
43+
end
44+
45+
---@private
46+
function Render:icon()
4147
local icon = self.checkbox.icon
4248
local text = self.inline and icon or str.pad_to(self.info.text, icon) .. icon
4349
self.marks:add(true, self.info.start_row, self.info.start_col, {
@@ -49,4 +55,21 @@ function Render:render()
4955
})
5056
end
5157

58+
---@private
59+
function Render:highlight_scope()
60+
local highlight = self.checkbox.scope_highlight
61+
if highlight == nil then
62+
return
63+
end
64+
local paragraph = self.info:sibling('paragraph')
65+
if paragraph == nil then
66+
return
67+
end
68+
self.marks:add(true, paragraph.start_row, paragraph.start_col, {
69+
end_row = paragraph.end_row,
70+
end_col = paragraph.end_col,
71+
hl_group = highlight,
72+
})
73+
end
74+
5275
return Render

lua/render-markdown/state.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,13 @@ function M.validate()
189189
validator
190190
:spec(path, config, { 'checkbox', 'unchecked' }, nilable)
191191
:type({ 'icon', 'highlight' }, 'string')
192+
:type('scope_highlight', { 'string', 'nil' })
193+
:check()
194+
validator
195+
:spec(path, config, { 'checkbox', 'checked' }, nilable)
196+
:type({ 'icon', 'highlight' }, 'string')
197+
:type('scope_highlight', { 'string', 'nil' })
192198
:check()
193-
validator:spec(path, config, { 'checkbox', 'checked' }, nilable):type({ 'icon', 'highlight' }, 'string'):check()
194199
validator:spec(path, config, { 'checkbox', 'custom' }, nilable):for_each(function(spec)
195200
spec:type({ 'raw', 'rendered', 'highlight' }, 'string'):check()
196201
end)

lua/render-markdown/types.lua

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@
5050
---@field public row string
5151
---@field public filler string
5252

53-
---@class (exact) render.md.CustomComponent
54-
---@field public raw string
55-
---@field public rendered string
56-
---@field public highlight string
57-
5853
---@class (exact) render.md.Quote
5954
---@field public enabled boolean
6055
---@field public icon string
6156
---@field public repeat_linebreak boolean
6257
---@field public highlight string
6358

59+
---@class (exact) render.md.CustomComponent
60+
---@field public raw string
61+
---@field public rendered string
62+
---@field public highlight string
63+
6464
---@class (exact) render.md.CheckboxComponent
6565
---@field public icon string
6666
---@field public highlight string
67+
---@field public scope_highlight? string
6768

6869
---@class (exact) render.md.Checkbox
6970
---@field public enabled boolean

scripts/update.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ def to_public_lines(self) -> list[str]:
3535
return []
3636
lines: list[str] = [self.name.replace("User", "")]
3737
for field in self.fields:
38-
if "ConfigOverrides" in self.name:
38+
if "scope_highlight" in field:
39+
lines.append(field)
40+
elif "ConfigOverrides" in self.name:
3941
lines.append(field.replace("?", ""))
4042
else:
4143
lines.append(field.replace("User", "").replace("?", ""))

0 commit comments

Comments
 (0)