Skip to content

Commit b84a788

Browse files
feature: Allow each individual component to be disabled
## Details Now that each component is defined in its own configuration we can add an `enabled` flag to each to allow them to be enabled / disabled. This has been added to: - heading - code - dash - bullet - checkbox - quote - pipe_table There are a couple of slightly unintuitive behaviors that I'll note down here. - Disabling quote also disables callouts. This is because callouts are essentially a special block quote. So if block quote rendering is disabled it makes no sense to render callouts. This does mean you can't have quote rendering without callouts, though this seems like an unlikely feature request. - Disabling checkboxes re-enables their list like behavior. Meaning bullet points will now be rendered at the start of checkboxes like normal list items rather than being concealed. - Disabling both checkboxes and bullets will then disable any rendering on checkbox elements. This is the only feature that requires disabling two things to get a `raw` view.
1 parent 501e5e0 commit b84a788

File tree

8 files changed

+150
-14
lines changed

8 files changed

+150
-14
lines changed

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ require('render-markdown').setup({
172172
highlight = '@markup.math',
173173
},
174174
heading = {
175+
-- Turn on / off heading icon & background rendering
176+
enabled = true,
175177
-- Replaces '#+' of 'atx_h._marker'
176178
-- The number of '#' in the heading determines the 'level'
177179
-- The 'level' is used to index into the array using a cycle
@@ -188,6 +190,8 @@ require('render-markdown').setup({
188190
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
189191
},
190192
code = {
193+
-- Turn on / off code block & inline code rendering
194+
enabled = true,
191195
-- Determines how code blocks & inline code are rendered:
192196
-- none: disables all rendering
193197
-- normal: adds highlight group to code blocks & inline code
@@ -198,13 +202,17 @@ require('render-markdown').setup({
198202
highlight = 'ColorColumn',
199203
},
200204
dash = {
205+
-- Turn on / off thematic break rendering
206+
enabled = true,
201207
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
202208
-- The icon gets repeated across the window's width
203209
icon = '',
204210
-- Highlight for the whole line generated from the icon
205211
highlight = 'LineNr',
206212
},
207213
bullet = {
214+
-- Turn on / off list bullet rendering
215+
enabled = true,
208216
-- Replaces '-'|'+'|'*' of 'list_item'
209217
-- How deeply nested the list is determines the 'level'
210218
-- The 'level' is used to index into the array using a cycle
@@ -216,6 +224,8 @@ require('render-markdown').setup({
216224
-- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link'
217225
-- There are two special states for unchecked & checked defined in the markdown grammar
218226
checkbox = {
227+
-- Turn on / off checkbox state rendering
228+
enabled = true,
219229
unchecked = {
220230
-- Replaces '[ ]' of 'task_list_marker_unchecked'
221231
icon = '󰄱 ',
@@ -240,12 +250,16 @@ require('render-markdown').setup({
240250
},
241251
},
242252
quote = {
253+
-- Turn on / off block quote & callout rendering
254+
enabled = true,
243255
-- Replaces '>' of 'block_quote'
244256
icon = '',
245257
-- Highlight for the quote icon
246258
highlight = '@markup.quote',
247259
},
248260
pipe_table = {
261+
-- Turn on / off pipe table rendering
262+
enabled = true,
249263
-- Determines how the table as a whole is rendered:
250264
-- none: disables all rendering
251265
-- normal: applies the 'cell' style rendering to each row of the table
@@ -293,7 +307,7 @@ require('render-markdown').setup({
293307
quote = { raw = '[!QUOTE]', rendered = '󱆨 Quote', highlight = '@markup.quote' },
294308
},
295309
link = {
296-
-- Turn on / off inline link icon behavior
310+
-- Turn on / off inline link icon rendering
297311
enabled = true,
298312
-- Inlined with 'image' elements
299313
image = '󰥶 ',
@@ -339,6 +353,8 @@ We use the following definitions when discussing indexing into arrays:
339353
```lua
340354
require('render-markdown').setup({
341355
heading = {
356+
-- Turn on / off heading icon & background rendering
357+
enabled = true,
342358
-- Replaces '#+' of 'atx_h._marker'
343359
-- The number of '#' in the heading determines the 'level'
344360
-- The 'level' is used to index into the array using a cycle
@@ -362,6 +378,8 @@ require('render-markdown').setup({
362378
```lua
363379
require('render-markdown').setup({
364380
code = {
381+
-- Turn on / off code block & inline code rendering
382+
enabled = true,
365383
-- Determines how code blocks & inline code are rendered:
366384
-- none: disables all rendering
367385
-- normal: adds highlight group to code blocks & inline code
@@ -379,6 +397,8 @@ require('render-markdown').setup({
379397
```lua
380398
require('render-markdown').setup({
381399
dash = {
400+
-- Turn on / off thematic break rendering
401+
enabled = true,
382402
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
383403
-- The icon gets repeated across the window's width
384404
icon = '',
@@ -393,6 +413,8 @@ require('render-markdown').setup({
393413
```lua
394414
require('render-markdown').setup({
395415
bullet = {
416+
-- Turn on / off list bullet rendering
417+
enabled = true,
396418
-- Replaces '-'|'+'|'*' of 'list_item'
397419
-- How deeply nested the list is determines the 'level'
398420
-- The 'level' is used to index into the array using a cycle
@@ -411,6 +433,8 @@ require('render-markdown').setup({
411433
-- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link'
412434
-- There are two special states for unchecked & checked defined in the markdown grammar
413435
checkbox = {
436+
-- Turn on / off checkbox state rendering
437+
enabled = true,
414438
unchecked = {
415439
-- Replaces '[ ]' of 'task_list_marker_unchecked'
416440
icon = '󰄱 ',
@@ -442,6 +466,8 @@ require('render-markdown').setup({
442466
```lua
443467
require('render-markdown').setup({
444468
quote = {
469+
-- Turn on / off block quote & callout rendering
470+
enabled = true,
445471
-- Replaces '>' of 'block_quote'
446472
icon = '',
447473
-- Highlight for the quote icon
@@ -455,6 +481,8 @@ require('render-markdown').setup({
455481
```lua
456482
require('render-markdown').setup({
457483
pipe_table = {
484+
-- Turn on / off pipe table rendering
485+
enabled = true,
458486
-- Determines how the table as a whole is rendered:
459487
-- none: disables all rendering
460488
-- normal: applies the 'cell' style rendering to each row of the table
@@ -516,7 +544,7 @@ require('render-markdown').setup({
516544
```lua
517545
require('render-markdown').setup({
518546
link = {
519-
-- Turn on / off inline link icon behavior
547+
-- Turn on / off inline link icon rendering
520548
enabled = true,
521549
-- Inlined with 'image' elements
522550
image = '󰥶 ',

doc/render-markdown.txt

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,8 @@ Full Default Configuration ~
209209
highlight = '@markup.math',
210210
},
211211
heading = {
212+
-- Turn on / off heading icon & background rendering
213+
enabled = true,
212214
-- Replaces '#+' of 'atx_h._marker'
213215
-- The number of '#' in the heading determines the 'level'
214216
-- The 'level' is used to index into the array using a cycle
@@ -225,6 +227,8 @@ Full Default Configuration ~
225227
foregrounds = { 'markdownH1', 'markdownH2', 'markdownH3', 'markdownH4', 'markdownH5', 'markdownH6' },
226228
},
227229
code = {
230+
-- Turn on / off code block & inline code rendering
231+
enabled = true,
228232
-- Determines how code blocks & inline code are rendered:
229233
-- none: disables all rendering
230234
-- normal: adds highlight group to code blocks & inline code
@@ -235,13 +239,17 @@ Full Default Configuration ~
235239
highlight = 'ColorColumn',
236240
},
237241
dash = {
242+
-- Turn on / off thematic break rendering
243+
enabled = true,
238244
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
239245
-- The icon gets repeated across the window's width
240246
icon = '─',
241247
-- Highlight for the whole line generated from the icon
242248
highlight = 'LineNr',
243249
},
244250
bullet = {
251+
-- Turn on / off list bullet rendering
252+
enabled = true,
245253
-- Replaces '-'|'+'|'*' of 'list_item'
246254
-- How deeply nested the list is determines the 'level'
247255
-- The 'level' is used to index into the array using a cycle
@@ -253,6 +261,8 @@ Full Default Configuration ~
253261
-- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link'
254262
-- There are two special states for unchecked & checked defined in the markdown grammar
255263
checkbox = {
264+
-- Turn on / off checkbox state rendering
265+
enabled = true,
256266
unchecked = {
257267
-- Replaces '[ ]' of 'task_list_marker_unchecked'
258268
icon = '󰄱 ',
@@ -277,12 +287,16 @@ Full Default Configuration ~
277287
},
278288
},
279289
quote = {
290+
-- Turn on / off block quote & callout rendering
291+
enabled = true,
280292
-- Replaces '>' of 'block_quote'
281293
icon = '▋',
282294
-- Highlight for the quote icon
283295
highlight = '@markup.quote',
284296
},
285297
pipe_table = {
298+
-- Turn on / off pipe table rendering
299+
enabled = true,
286300
-- Determines how the table as a whole is rendered:
287301
-- none: disables all rendering
288302
-- normal: applies the 'cell' style rendering to each row of the table
@@ -330,7 +344,7 @@ Full Default Configuration ~
330344
quote = { raw = '[!QUOTE]', rendered = '󱆨 Quote', highlight = '@markup.quote' },
331345
},
332346
link = {
333-
-- Turn on / off inline link icon behavior
347+
-- Turn on / off inline link icon rendering
334348
enabled = true,
335349
-- Inlined with 'image' elements
336350
image = '󰥶 ',
@@ -375,6 +389,8 @@ HEADINGS *render-markdown-setup-headings*
375389
>lua
376390
require('render-markdown').setup({
377391
heading = {
392+
-- Turn on / off heading icon & background rendering
393+
enabled = true,
378394
-- Replaces '#+' of 'atx_h._marker'
379395
-- The number of '#' in the heading determines the 'level'
380396
-- The 'level' is used to index into the array using a cycle
@@ -399,6 +415,8 @@ CODE BLOCKS *render-markdown-setup-code-blocks*
399415
>lua
400416
require('render-markdown').setup({
401417
code = {
418+
-- Turn on / off code block & inline code rendering
419+
enabled = true,
402420
-- Determines how code blocks & inline code are rendered:
403421
-- none: disables all rendering
404422
-- normal: adds highlight group to code blocks & inline code
@@ -417,6 +435,8 @@ DASHED LINE *render-markdown-setup-dashed-line*
417435
>lua
418436
require('render-markdown').setup({
419437
dash = {
438+
-- Turn on / off thematic break rendering
439+
enabled = true,
420440
-- Replaces '---'|'***'|'___'|'* * *' of 'thematic_break'
421441
-- The icon gets repeated across the window's width
422442
icon = '─',
@@ -432,6 +452,8 @@ LIST BULLETS *render-markdown-setup-list-bullets*
432452
>lua
433453
require('render-markdown').setup({
434454
bullet = {
455+
-- Turn on / off list bullet rendering
456+
enabled = true,
435457
-- Replaces '-'|'+'|'*' of 'list_item'
436458
-- How deeply nested the list is determines the 'level'
437459
-- The 'level' is used to index into the array using a cycle
@@ -451,6 +473,8 @@ CHECKBOXES *render-markdown-setup-checkboxes*
451473
-- Checkboxes are a special instance of a 'list_item' that start with a 'shortcut_link'
452474
-- There are two special states for unchecked & checked defined in the markdown grammar
453475
checkbox = {
476+
-- Turn on / off checkbox state rendering
477+
enabled = true,
454478
unchecked = {
455479
-- Replaces '[ ]' of 'task_list_marker_unchecked'
456480
icon = '󰄱 ',
@@ -483,6 +507,8 @@ BLOCK QUOTES *render-markdown-setup-block-quotes*
483507
>lua
484508
require('render-markdown').setup({
485509
quote = {
510+
-- Turn on / off block quote & callout rendering
511+
enabled = true,
486512
-- Replaces '>' of 'block_quote'
487513
icon = '▋',
488514
-- Highlight for the quote icon
@@ -497,6 +523,8 @@ TABLES *render-markdown-setup-tables*
497523
>lua
498524
require('render-markdown').setup({
499525
pipe_table = {
526+
-- Turn on / off pipe table rendering
527+
enabled = true,
500528
-- Determines how the table as a whole is rendered:
501529
-- none: disables all rendering
502530
-- normal: applies the 'cell' style rendering to each row of the table
@@ -560,7 +588,7 @@ LINKS *render-markdown-setup-links*
560588
>lua
561589
require('render-markdown').setup({
562590
link = {
563-
-- Turn on / off inline link icon behavior
591+
-- Turn on / off inline link icon rendering
564592
enabled = true,
565593
-- Inlined with 'image' elements
566594
image = '󰥶 ',

lua/render-markdown/handler/markdown.lua

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ M.render_node = function(namespace, buf, capture, node)
3030

3131
if capture == 'heading' then
3232
local heading = state.config.heading
33+
if not heading.enabled then
34+
return
35+
end
3336
local level = vim.fn.strdisplaywidth(value)
3437

3538
local icon = list.cycle(heading.icons, level)
@@ -57,14 +60,19 @@ M.render_node = function(namespace, buf, capture, node)
5760
})
5861
elseif capture == 'dash' then
5962
local dash = state.config.dash
63+
if not dash.enabled then
64+
return
65+
end
6066
local width = vim.api.nvim_win_get_width(util.buf_to_win(buf))
61-
6267
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, 0, {
6368
virt_text = { { dash.icon:rep(width), dash.highlight } },
6469
virt_text_pos = 'overlay',
6570
})
6671
elseif capture == 'code' then
6772
local code = state.config.code
73+
if not code.enabled then
74+
return
75+
end
6876
if not vim.tbl_contains({ 'normal', 'full' }, code.style) then
6977
return
7078
end
@@ -76,6 +84,9 @@ M.render_node = function(namespace, buf, capture, node)
7684
})
7785
elseif capture == 'language' then
7886
local code = state.config.code
87+
if not code.enabled then
88+
return
89+
end
7990
if not vim.tbl_contains({ 'language', 'full' }, code.style) then
8091
return
8192
end
@@ -111,6 +122,9 @@ M.render_node = function(namespace, buf, capture, node)
111122
})
112123
else
113124
local bullet = state.config.bullet
125+
if not bullet.enabled then
126+
return
127+
end
114128
-- List markers from tree-sitter should have leading spaces removed, however there are known
115129
-- edge cases in the parser: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/127
116130
-- As a result we handle leading spaces here, can remove if this gets fixed upstream
@@ -132,6 +146,9 @@ M.render_node = function(namespace, buf, capture, node)
132146
end
133147
elseif capture == 'quote_marker' then
134148
local quote = state.config.quote
149+
if not quote.enabled then
150+
return
151+
end
135152
local highlight = quote.highlight
136153
local quote_node = ts.parent_in_section(node, 'block_quote')
137154
if quote_node ~= nil then
@@ -147,18 +164,25 @@ M.render_node = function(namespace, buf, capture, node)
147164
virt_text_pos = 'overlay',
148165
})
149166
elseif vim.tbl_contains({ 'checkbox_unchecked', 'checkbox_checked' }, capture) then
150-
local checkbox = state.config.checkbox.unchecked
167+
local checkbox = state.config.checkbox
168+
if not checkbox.enabled then
169+
return
170+
end
171+
local checkbox_state = checkbox.unchecked
151172
if capture == 'checkbox_checked' then
152-
checkbox = state.config.checkbox.checked
173+
checkbox_state = checkbox.checked
153174
end
154175
vim.api.nvim_buf_set_extmark(buf, namespace, start_row, start_col, {
155176
end_row = end_row,
156177
end_col = end_col,
157-
virt_text = { { str.pad_to(value, checkbox.icon), checkbox.highlight } },
178+
virt_text = { { str.pad_to(value, checkbox_state.icon), checkbox_state.highlight } },
158179
virt_text_pos = 'overlay',
159180
})
160181
elseif capture == 'table' then
161182
local pipe_table = state.config.pipe_table
183+
if not pipe_table.enabled then
184+
return
185+
end
162186
if pipe_table.style ~= 'full' then
163187
return
164188
end
@@ -207,6 +231,9 @@ M.render_node = function(namespace, buf, capture, node)
207231
end
208232
elseif vim.tbl_contains({ 'table_head', 'table_delim', 'table_row' }, capture) then
209233
local pipe_table = state.config.pipe_table
234+
if not pipe_table.enabled then
235+
return
236+
end
210237
if pipe_table.style == 'none' then
211238
return
212239
end
@@ -261,6 +288,9 @@ end
261288
---@param node TSNode
262289
---@return boolean
263290
M.sibling_checkbox = function(buf, node)
291+
if not state.config.checkbox.enabled then
292+
return false
293+
end
264294
if ts.sibling(node, { 'task_list_marker_unchecked', 'task_list_marker_checked' }) ~= nil then
265295
return true
266296
end

0 commit comments

Comments
 (0)