Skip to content

Commit 7620d4e

Browse files
feat: allow users to disable code block delimiter concealing
## Details Request: #475 Among the changes introduced back in `0.11.0`, how the delimiter nodes around code blocks were handled was one them. Rather than a horizontal conceal a new vertical conceal was added which entirely removed those lines if conceal was enabled. In order to still allow borders to be rendered I needed a way to disable this feature while still allowing for concealing elsewhere. Luckily in the set of changes a way to dynamically turn off certain highlights was also added, which we use at startup to disable this behavior for users. While fixing all the odds and ends I decided to replicate the old behavior and apply a horizontal conceal over the various delimiter nodes, I didn't give much thought towards other approaches. This feature allows users who want those delimiter elements to still have them. To make this happen the following new options have been added: - `code.conceal_delimiters` - stops us from adding conceal over the delimiter nodes if set to `false` - `code.language` - a more direct way to disable language headings, functionally the same as `style = 'normal'` To get the backticks back these 2 must be set properly and `border` must also be disabled. This removes all the things that currently cover these nodes, final config ends up as: ```lua require('render-markdown').setup({ code = { conceal_delimiters = false, language = false, border = 'none', }, }) ```
1 parent 12d951d commit 7620d4e

File tree

6 files changed

+77
-46
lines changed

6 files changed

+77
-46
lines changed

README.md

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -435,24 +435,28 @@ require('render-markdown').setup({
435435
-- Turn on / off any sign column related rendering.
436436
sign = true,
437437
-- Determines how code blocks & inline code are rendered.
438-
-- | none | disables all rendering |
439-
-- | normal | highlight group to code blocks & inline code, adds padding to code blocks |
440-
-- | language | language icon to sign column if enabled and icon + name above code blocks |
441-
-- | full | normal + language |
438+
-- | none | disables all rendering |
439+
-- | normal | background highlighting + padding |
440+
-- | language | language heading with icon + sign column |
441+
-- | full | normal + language |
442442
style = 'full',
443+
-- Whether to conceal nodes at the top and bottom of code blocks.
444+
conceal_delimiters = true,
445+
-- Turn on / off any language heading related rendering.
446+
language = true,
443447
-- Determines where language icon is rendered.
444448
-- | right | right side of code block |
445449
-- | left | left side of code block |
446450
position = 'left',
447-
-- Amount of padding to add around the language.
448-
-- If a float < 1 is provided it is treated as a percentage of available window space.
449-
language_pad = 0,
450451
-- Whether to include the language icon above code blocks.
451452
language_icon = true,
452453
-- Whether to include the language name above code blocks.
453454
language_name = true,
454455
-- Whether to include the language info above code blocks.
455456
language_info = true,
457+
-- Amount of padding to add around the language.
458+
-- If a float < 1 is provided it is treated as a percentage of available window space.
459+
language_pad = 0,
456460
-- A list of language names for which background highlighting will be disabled.
457461
-- Likely because that language has background highlights itself.
458462
-- Use a boolean to make behavior apply to all languages.
@@ -1058,24 +1062,28 @@ require('render-markdown').setup({
10581062
-- Turn on / off any sign column related rendering.
10591063
sign = true,
10601064
-- Determines how code blocks & inline code are rendered.
1061-
-- | none | disables all rendering |
1062-
-- | normal | highlight group to code blocks & inline code, adds padding to code blocks |
1063-
-- | language | language icon to sign column if enabled and icon + name above code blocks |
1064-
-- | full | normal + language |
1065+
-- | none | disables all rendering |
1066+
-- | normal | background highlighting + padding |
1067+
-- | language | language heading with icon + sign column |
1068+
-- | full | normal + language |
10651069
style = 'full',
1070+
-- Whether to conceal nodes at the top and bottom of code blocks.
1071+
conceal_delimiters = true,
1072+
-- Turn on / off any language heading related rendering.
1073+
language = true,
10661074
-- Determines where language icon is rendered.
10671075
-- | right | right side of code block |
10681076
-- | left | left side of code block |
10691077
position = 'left',
1070-
-- Amount of padding to add around the language.
1071-
-- If a float < 1 is provided it is treated as a percentage of available window space.
1072-
language_pad = 0,
10731078
-- Whether to include the language icon above code blocks.
10741079
language_icon = true,
10751080
-- Whether to include the language name above code blocks.
10761081
language_name = true,
10771082
-- Whether to include the language info above code blocks.
10781083
language_info = true,
1084+
-- Amount of padding to add around the language.
1085+
-- If a float < 1 is provided it is treated as a percentage of available window space.
1086+
language_pad = 0,
10791087
-- A list of language names for which background highlighting will be disabled.
10801088
-- Likely because that language has background highlights itself.
10811089
-- Use a boolean to make behavior apply to all languages.

doc/render-markdown.txt

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.2 Last change: 2025 July 15
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 17
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -501,24 +501,28 @@ Default Configuration ~
501501
-- Turn on / off any sign column related rendering.
502502
sign = true,
503503
-- Determines how code blocks & inline code are rendered.
504-
-- | none | disables all rendering |
505-
-- | normal | highlight group to code blocks & inline code, adds padding to code blocks |
506-
-- | language | language icon to sign column if enabled and icon + name above code blocks |
507-
-- | full | normal + language |
504+
-- | none | disables all rendering |
505+
-- | normal | background highlighting + padding |
506+
-- | language | language heading with icon + sign column |
507+
-- | full | normal + language |
508508
style = 'full',
509+
-- Whether to conceal nodes at the top and bottom of code blocks.
510+
conceal_delimiters = true,
511+
-- Turn on / off any language heading related rendering.
512+
language = true,
509513
-- Determines where language icon is rendered.
510514
-- | right | right side of code block |
511515
-- | left | left side of code block |
512516
position = 'left',
513-
-- Amount of padding to add around the language.
514-
-- If a float < 1 is provided it is treated as a percentage of available window space.
515-
language_pad = 0,
516517
-- Whether to include the language icon above code blocks.
517518
language_icon = true,
518519
-- Whether to include the language name above code blocks.
519520
language_name = true,
520521
-- Whether to include the language info above code blocks.
521522
language_info = true,
523+
-- Amount of padding to add around the language.
524+
-- If a float < 1 is provided it is treated as a percentage of available window space.
525+
language_pad = 0,
522526
-- A list of language names for which background highlighting will be disabled.
523527
-- Likely because that language has background highlights itself.
524528
-- Use a boolean to make behavior apply to all languages.
@@ -1118,24 +1122,28 @@ Code Block Configuration ~
11181122
-- Turn on / off any sign column related rendering.
11191123
sign = true,
11201124
-- Determines how code blocks & inline code are rendered.
1121-
-- | none | disables all rendering |
1122-
-- | normal | highlight group to code blocks & inline code, adds padding to code blocks |
1123-
-- | language | language icon to sign column if enabled and icon + name above code blocks |
1124-
-- | full | normal + language |
1125+
-- | none | disables all rendering |
1126+
-- | normal | background highlighting + padding |
1127+
-- | language | language heading with icon + sign column |
1128+
-- | full | normal + language |
11251129
style = 'full',
1130+
-- Whether to conceal nodes at the top and bottom of code blocks.
1131+
conceal_delimiters = true,
1132+
-- Turn on / off any language heading related rendering.
1133+
language = true,
11261134
-- Determines where language icon is rendered.
11271135
-- | right | right side of code block |
11281136
-- | left | left side of code block |
11291137
position = 'left',
1130-
-- Amount of padding to add around the language.
1131-
-- If a float < 1 is provided it is treated as a percentage of available window space.
1132-
language_pad = 0,
11331138
-- Whether to include the language icon above code blocks.
11341139
language_icon = true,
11351140
-- Whether to include the language name above code blocks.
11361141
language_name = true,
11371142
-- Whether to include the language info above code blocks.
11381143
language_info = true,
1144+
-- Amount of padding to add around the language.
1145+
-- If a float < 1 is provided it is treated as a percentage of available window space.
1146+
language_pad = 0,
11391147
-- A list of language names for which background highlighting will be disabled.
11401148
-- Likely because that language has background highlights itself.
11411149
-- Use a boolean to make behavior apply to all languages.

lua/render-markdown/config/code.lua

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
---@class (exact) render.md.code.Config: render.md.base.Config
22
---@field sign boolean
33
---@field style render.md.code.Style
4+
---@field conceal_delimiters boolean
5+
---@field language boolean
46
---@field position render.md.code.Position
5-
---@field language_pad number
67
---@field language_icon boolean
78
---@field language_name boolean
89
---@field language_info boolean
10+
---@field language_pad number
911
---@field disable_background boolean|string[]
1012
---@field width render.md.code.Width
1113
---@field left_margin number
@@ -68,24 +70,28 @@ M.default = {
6870
-- Turn on / off any sign column related rendering.
6971
sign = true,
7072
-- Determines how code blocks & inline code are rendered.
71-
-- | none | disables all rendering |
72-
-- | normal | highlight group to code blocks & inline code, adds padding to code blocks |
73-
-- | language | language icon to sign column if enabled and icon + name above code blocks |
74-
-- | full | normal + language |
73+
-- | none | disables all rendering |
74+
-- | normal | background highlighting + padding |
75+
-- | language | language heading with icon + sign column |
76+
-- | full | normal + language |
7577
style = 'full',
78+
-- Whether to conceal nodes at the top and bottom of code blocks.
79+
conceal_delimiters = true,
80+
-- Turn on / off any language heading related rendering.
81+
language = true,
7682
-- Determines where language icon is rendered.
7783
-- | right | right side of code block |
7884
-- | left | left side of code block |
7985
position = 'left',
80-
-- Amount of padding to add around the language.
81-
-- If a float < 1 is provided it is treated as a percentage of available window space.
82-
language_pad = 0,
8386
-- Whether to include the language icon above code blocks.
8487
language_icon = true,
8588
-- Whether to include the language name above code blocks.
8689
language_name = true,
8790
-- Whether to include the language info above code blocks.
8891
language_info = true,
92+
-- Amount of padding to add around the language.
93+
-- If a float < 1 is provided it is treated as a percentage of available window space.
94+
language_pad = 0,
8995
-- A list of language names for which background highlighting will be disabled.
9096
-- Likely because that language has background highlights itself.
9197
-- Use a boolean to make behavior apply to all languages.
@@ -148,11 +154,13 @@ function M.validate(spec)
148154
require('render-markdown.config.base').validate(spec)
149155
spec:type('sign', 'boolean')
150156
spec:one_of('style', vim.tbl_values(Style))
157+
spec:type('conceal_delimiters', 'boolean')
158+
spec:type('language', 'boolean')
151159
spec:one_of('position', vim.tbl_values(Position))
152-
spec:type('language_pad', 'number')
153160
spec:type('language_icon', 'boolean')
154161
spec:type('language_name', 'boolean')
155162
spec:type('language_info', 'boolean')
163+
spec:type('language_pad', 'number')
156164
spec:list('disable_background', 'string', 'boolean')
157165
spec:one_of('width', vim.tbl_values(Width))
158166
spec:type('left_margin', 'number')

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.6.4'
8+
M.version = '8.6.5'
99

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

lua/render-markdown/render/markdown/code.lua

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ end
7272
---@protected
7373
function Render:run()
7474
local start_row = self.node.start_row
75-
local above = self.node:child('fenced_code_block_delimiter', start_row)
76-
self.marks:over(true, above, { conceal = '' })
77-
7875
local end_row = self.node.end_row - 1
79-
local below = self.node:child('fenced_code_block_delimiter', end_row)
80-
self.marks:over(true, below, { conceal = '' })
8176

77+
local above = self.node:child('fenced_code_block_delimiter', start_row)
78+
local below = self.node:child('fenced_code_block_delimiter', end_row)
8279
local info = self.node:child('info_string')
83-
self.marks:over(true, info, { conceal = '' })
80+
81+
if self.config.conceal_delimiters then
82+
self.marks:over(true, above, { conceal = '' })
83+
self.marks:over(true, below, { conceal = '' })
84+
self.marks:over(true, info, { conceal = '' })
85+
end
8486

8587
local language = info and info:child('language')
8688
if not self:language(info, language, above) then
@@ -104,6 +106,9 @@ function Render:language(info, language, delim)
104106
if not vim.tbl_contains({ 'language', 'full' }, self.config.style) then
105107
return false
106108
end
109+
if not self.config.language then
110+
return false
111+
end
107112
if not info or not language or not delim then
108113
return false
109114
end

lua/render-markdown/types.lua

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@
8686
---@class (exact) render.md.code.UserConfig: render.md.base.UserConfig
8787
---@field sign? boolean
8888
---@field style? render.md.code.Style
89+
---@field conceal_delimiters? boolean
90+
---@field language? boolean
8991
---@field position? render.md.code.Position
90-
---@field language_pad? number
9192
---@field language_icon? boolean
9293
---@field language_name? boolean
9394
---@field language_info? boolean
95+
---@field language_pad? number
9496
---@field disable_background? boolean|string[]
9597
---@field width? render.md.code.Width
9698
---@field left_margin? number

0 commit comments

Comments
 (0)