Skip to content

Commit 90637a1

Browse files
Add support for overlaying checkbox icons
# Details Pulls in the checkbox replacement logic from PR: #13 Updates documentation and demo. Slight change to agg font selection. Co-Authored-By: Dmitriy <[email protected]>
1 parent af819f3 commit 90637a1

File tree

8 files changed

+87
-3
lines changed

8 files changed

+87
-3
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Plugin to improve viewing Markdown files in Neovim
1414
- Updates horizontal breaks with full-width lines
1515
- Highlights code blocks and inline code to better stand out
1616
- Replaces bullet points with provided character based on level
17+
- Replaces checkboxes with provided characters based on whether they are checked
1718
- Replaces block quote leading `>` with provided character
1819
- Updates table borders with better border characters, does NOT automatically align
1920
- Basic support for `LaTeX` if `pylatexenc` is installed on system
@@ -69,6 +70,9 @@ require('render-markdown').setup({
6970
(list_marker_star)
7071
] @list_marker
7172
73+
(task_list_marker_unchecked) @checkbox_unchecked
74+
(task_list_marker_checked) @checkbox_checked
75+
7276
(block_quote (block_quote_marker) @quote_marker)
7377
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
7478
@@ -92,6 +96,12 @@ require('render-markdown').setup({
9296
dash = '',
9397
-- Character to use for the bullet points in lists
9498
bullets = { '', '', '', '' },
99+
checkbox = {
100+
-- Character that will replace the [ ] in unchecked checkboxes
101+
unchecked = '󰄱 ',
102+
-- Character that will replace the [x] in checked checkboxes
103+
checked = '',
104+
},
95105
-- Character that will replace the > at the start of block quotes
96106
quote = '',
97107
-- See :h 'conceallevel' for more information about meaning of values
@@ -124,6 +134,12 @@ require('render-markdown').setup({
124134
code = 'ColorColumn',
125135
-- Bullet points in list
126136
bullet = 'Normal',
137+
checkbox = {
138+
-- Unchecked checkboxes
139+
unchecked = '@markup.list.unchecked',
140+
-- Checked checkboxes
141+
checked = '@markup.heading',
142+
},
127143
table = {
128144
-- Header of a markdown table
129145
head = '@markup.heading',

demo/demo.gif

79.5 KB
Loading

demo/sample.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ if __name__ == "__main__":
3333
2. Item 2
3434
3. Item 3
3535

36+
- [ ] Unchecked Checkbox
37+
- [x] Checked Checkbox
38+
3639
---
3740

3841
> Quote line 1

doc/render-markdown.txt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.9.5 Last change: 2024 April 11
1+
*render-markdown.txt* For 0.9.5 Last change: 2024 April 13
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -34,6 +34,7 @@ Plugin to improve viewing Markdown files in Neovim
3434
- Updates horizontal breaks with full-width lines
3535
- Highlights code blocks and inline code to better stand out
3636
- Replaces bullet points with provided character based on level
37+
- Replaces checkboxes with provided characters based on whether they are checked
3738
- Replaces block quote leading `>` with provided character
3839
- Updates table borders with better border characters, does NOT automatically align
3940
- Basic support for `LaTeX` if `pylatexenc` is installed on system
@@ -96,6 +97,9 @@ modified by the user.
9697
(list_marker_star)
9798
] @list_marker
9899

100+
(task_list_marker_unchecked) @checkbox_unchecked
101+
(task_list_marker_checked) @checkbox_checked
102+
99103
(block_quote (block_quote_marker) @quote_marker)
100104
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
101105

@@ -119,6 +123,12 @@ modified by the user.
119123
dash = '—',
120124
-- Character to use for the bullet points in lists
121125
bullets = { '●', '○', '◆', '◇' },
126+
checkbox = {
127+
-- Character that will replace the [ ] in unchecked checkboxes
128+
unchecked = '󰄱 ',
129+
-- Character that will replace the [x] in checked checkboxes
130+
checked = ' ',
131+
},
122132
-- Character that will replace the > at the start of block quotes
123133
quote = '┃',
124134
-- See :h 'conceallevel' for more information about meaning of values
@@ -151,6 +161,12 @@ modified by the user.
151161
code = 'ColorColumn',
152162
-- Bullet points in list
153163
bullet = 'Normal',
164+
checkbox = {
165+
-- Unchecked checkboxes
166+
unchecked = '@markup.list.unchecked',
167+
-- Checked checkboxes
168+
checked = '@markup.heading',
169+
},
154170
table = {
155171
-- Header of a markdown table
156172
head = '@markup.heading',

justfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
default_zoom := '3'
1+
default_zoom := '2'
22

33
demo zoom=default_zoom:
44
rm -f demo/demo.gif
@@ -8,7 +8,7 @@ demo zoom=default_zoom:
88
--cast demo.cast
99
# https://docs.asciinema.org/manual/agg/usage/
1010
agg demo.cast demo/demo.gif \
11-
--font-family "JetBrainsMono NFM" \
11+
--font-family "Monaspace Neon,Hack Nerd Font" \
1212
--last-frame-duration 1
1313
rm demo.cast
1414

lua/render-markdown/handler/markdown.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ M.render = function(namespace, root)
7070
virt_text = { virt_text },
7171
virt_text_pos = 'overlay',
7272
})
73+
elseif vim.tbl_contains({ 'checkbox_unchecked', 'checkbox_checked' }, capture) then
74+
local checkbox = state.config.checkbox.unchecked
75+
local highlight = highlights.checkbox.unchecked
76+
if capture == 'checkbox_checked' then
77+
checkbox = state.config.checkbox.checked
78+
highlight = highlights.checkbox.checked
79+
end
80+
local padding = vim.fn.strdisplaywidth(value) - vim.fn.strdisplaywidth(checkbox)
81+
82+
if padding >= 0 then
83+
local virt_text = { string.rep(' ', padding) .. checkbox, highlight }
84+
vim.api.nvim_buf_set_extmark(0, namespace, start_row, start_col, {
85+
end_row = end_row,
86+
end_col = end_col,
87+
virt_text = { virt_text },
88+
virt_text_pos = 'overlay',
89+
})
90+
end
7391
elseif capture == 'table' then
7492
if state.config.fat_tables then
7593
local lines = vim.api.nvim_buf_get_lines(0, start_row, end_row, false)

lua/render-markdown/init.lua

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ local M = {}
77
---@field public head? string
88
---@field public row? string
99

10+
---@class UserCheckboxHighlights
11+
---@field public unchecked? string
12+
---@field public checked? string
13+
1014
---@class UserHeadingHighlights
1115
---@field public backgrounds? string[]
1216
---@field public foregrounds? string[]
@@ -16,6 +20,7 @@ local M = {}
1620
---@field public dash? string
1721
---@field public code? string
1822
---@field public bullet? string
23+
---@field public checkbox? UserCheckboxHighlights
1924
---@field public table? UserTableHighlights
2025
---@field public latex? string
2126
---@field public quote? string
@@ -24,6 +29,10 @@ local M = {}
2429
---@field public default? integer
2530
---@field public rendered? integer
2631

32+
---@class UserCheckbox
33+
---@field public unchecked? string
34+
---@field public checked? string
35+
2736
---@class UserConfig
2837
---@field public markdown_query? string
2938
---@field public inline_query? string
@@ -32,6 +41,7 @@ local M = {}
3241
---@field public headings? string[]
3342
---@field public dash? string
3443
---@field public bullets? string[]
44+
---@field public checkbox? UserCheckbox
3545
---@field public quote? string
3646
---@field public conceal? UserConceal
3747
---@field public fat_tables? boolean
@@ -61,6 +71,9 @@ function M.setup(opts)
6171
(list_marker_star)
6272
] @list_marker
6373
74+
(task_list_marker_unchecked) @checkbox_unchecked
75+
(task_list_marker_checked) @checkbox_checked
76+
6477
(block_quote (block_quote_marker) @quote_marker)
6578
(block_quote (paragraph (inline (block_continuation) @quote_marker)))
6679
@@ -77,6 +90,10 @@ function M.setup(opts)
7790
headings = { '󰲡 ', '󰲣 ', '󰲥 ', '󰲧 ', '󰲩 ', '󰲫 ' },
7891
dash = '',
7992
bullets = { '', '', '', '' },
93+
checkbox = {
94+
unchecked = '󰄱 ',
95+
checked = '',
96+
},
8097
quote = '',
8198
conceal = {
8299
default = vim.opt.conceallevel:get(),
@@ -98,6 +115,10 @@ function M.setup(opts)
98115
dash = 'LineNr',
99116
code = 'ColorColumn',
100117
bullet = 'Normal',
118+
checkbox = {
119+
unchecked = '@markup.list.unchecked',
120+
checked = '@markup.heading',
121+
},
101122
table = {
102123
head = '@markup.heading',
103124
row = 'Normal',

lua/render-markdown/state.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
---@field public head string
33
---@field public row string
44

5+
---@class CheckboxHighlights
6+
---@field public unchecked string
7+
---@field public checked string
8+
59
---@class HeadingHighlights
610
---@field public backgrounds string[]
711
---@field public foregrounds string[]
@@ -11,6 +15,7 @@
1115
---@field public dash string
1216
---@field public code string
1317
---@field public bullet string
18+
---@field public checkbox CheckboxHighlights
1419
---@field public table TableHighlights
1520
---@field public latex string
1621
---@field public quote string
@@ -19,6 +24,10 @@
1924
---@field public default integer
2025
---@field public rendered integer
2126

27+
---@class Checkbox
28+
---@field public unchecked string
29+
---@field public checked string
30+
2231
---@class Config
2332
---@field public markdown_query string
2433
---@field public inline_query string
@@ -27,6 +36,7 @@
2736
---@field public headings string[]
2837
---@field public dash string
2938
---@field public bullets string[]
39+
---@field public checkbox Checkbox
3040
---@field public quote string
3141
---@field public conceal Conceal
3242
---@field public fat_tables boolean

0 commit comments

Comments
 (0)