Skip to content

Commit fb6b3d1

Browse files
feat: user configurable anti conceal per component
## Details Request: #204 Previously the decoration elements that are hidden on the cursor line was not something the user had direct control over. The default behavior was to never hide virtual lines, spacing, signs or code backgrounds. All other decorations on the line would always be hidden if the user kept anti conceal enabled. For the time being virtual lines and spacing remain permanently enabled. However signs, code backgrounds and most other elements that by default would be hidden are entirely within the users control. This is all managed through the new `anti_conceal.ignore` property. This table is a mapping from element name to a boolean. A value of `true` for an element means it will not be concealed when the cursor enters the line. A value of `false` behaves the same as no value being set and will be hidden. A table is used rather than a list so that when users modify values the defaults remain the same as they were unless explicitely changed. Signs and code backgrounds set their values to `true` to remain ignored by default as before, however now users have the ability to change this behavior if they would like to hide signs and backgrounds. Additionally most other decorations that remain concealable by default like before can now be ignored if the user sets their value to true. A complete list of possible values is provided in the default configuration in the README.
1 parent 18c7ef7 commit fb6b3d1

21 files changed

+108
-41
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
- allow empty lists for all heading properties [0c6de74](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/0c6de743a8d3c61b87bc7db9ab97dcda12ca6818)
1111
- wiki link config & language highlight [#205](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/205)
1212
[965c222](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/965c222076b2d289ed498730845d533780f3c7c7)
13+
- code language name [#205](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/205)
14+
[18c7ef7](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/18c7ef71fb4b8d83cb0160adc9127fc4d65ca42e)
1315

1416
### Bug Fixes
1517

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ require('render-markdown').setup({
169169
anti_conceal = {
170170
-- This enables hiding any added text on the line the cursor is on
171171
enabled = true,
172+
-- Which elements to always show, ignoring anti conceal behavior. Possible values are:
173+
-- head_icon, head_background, head_border, code_language, code_background, code_border
174+
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
175+
ignore = {
176+
code_background = true,
177+
sign = true,
178+
},
172179
-- Number of lines above cursor to show
173180
above = 0,
174181
-- Number of lines below cursor to show

doc/render-markdown.txt

Lines changed: 8 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 October 12
1+
*render-markdown.txt* For 0.10.0 Last change: 2024 October 13
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -218,6 +218,13 @@ Default Configuration ~
218218
anti_conceal = {
219219
-- This enables hiding any added text on the line the cursor is on
220220
enabled = true,
221+
-- Which elements to always show, ignoring anti conceal behavior. Possible values are:
222+
-- head_icon, head_background, head_border, code_language, code_background, code_border
223+
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
224+
ignore = {
225+
code_background = true,
226+
sign = true,
227+
},
221228
-- Number of lines above cursor to show
222229
above = 0,
223230
-- Number of lines below cursor to show

lua/render-markdown/core/list.lua

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ local log = require('render-markdown.core.log')
22
local util = require('render-markdown.core.util')
33

44
---@class render.md.Marks
5+
---@field private ignore table<render.md.Element, boolean>
56
---@field private marks render.md.Mark[]
67
local Marks = {}
78
Marks.__index = Marks
89

10+
---@param ignore table<render.md.Element, boolean>
911
---@return render.md.Marks
10-
function Marks.new()
12+
function Marks.new(ignore)
1113
local self = setmetatable({}, Marks)
14+
self.ignore = ignore
1215
self.marks = {}
1316
return self
1417
end
@@ -18,15 +21,15 @@ function Marks:get()
1821
return self.marks
1922
end
2023

21-
---@param conceal boolean
24+
---@param element boolean|render.md.Element
2225
---@param start_row integer
2326
---@param start_col integer
2427
---@param opts vim.api.keyset.set_extmark
2528
---@return boolean
26-
function Marks:add(conceal, start_row, start_col, opts)
29+
function Marks:add(element, start_row, start_col, opts)
2730
---@type render.md.Mark
2831
local mark = {
29-
conceal = conceal,
32+
conceal = self:conceal(element),
3033
start_row = start_row,
3134
start_col = start_col,
3235
opts = opts,
@@ -44,12 +47,24 @@ function Marks:add(conceal, start_row, start_col, opts)
4447
return true
4548
end
4649

50+
---@private
51+
---@param element boolean|render.md.Element
52+
---@return boolean
53+
function Marks:conceal(element)
54+
if type(element) == 'boolean' then
55+
return element
56+
else
57+
return self.ignore[element] ~= true
58+
end
59+
end
60+
4761
---@class render.md.ListHelper
4862
local M = {}
4963

64+
---@param ignore? table<render.md.Element, boolean>
5065
---@return render.md.Marks
51-
function M.new_marks()
52-
return Marks.new()
66+
function M.new_marks(ignore)
67+
return Marks.new(ignore or {})
5368
end
5469

5570
---@generic T

lua/render-markdown/handler/markdown.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ local state = require('render-markdown.state')
44
local treesitter = require('render-markdown.core.treesitter')
55

66
---@class render.md.handler.buf.Markdown
7-
---@field private marks render.md.Marks
87
---@field private config render.md.buffer.Config
98
---@field private context render.md.Context
9+
---@field private marks render.md.Marks
1010
---@field private query vim.treesitter.Query
1111
---@field private renderers table<string, render.md.Renderer>
1212
local Handler = {}
@@ -16,9 +16,9 @@ Handler.__index = Handler
1616
---@return render.md.handler.buf.Markdown
1717
function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
19-
self.marks = list.new_marks()
2019
self.config = state.get(buf)
2120
self.context = Context.get(buf)
21+
self.marks = list.new_marks(self.config.anti_conceal.ignore)
2222
self.query = treesitter.parse(
2323
'markdown',
2424
[[

lua/render-markdown/handler/markdown_inline.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ local state = require('render-markdown.state')
44
local treesitter = require('render-markdown.core.treesitter')
55

66
---@class render.md.handler.buf.MarkdownInline
7-
---@field private marks render.md.Marks
87
---@field private config render.md.buffer.Config
98
---@field private context render.md.Context
9+
---@field private marks render.md.Marks
1010
---@field private query vim.treesitter.Query
1111
---@field private renderers table<string, render.md.Renderer>
1212
local Handler = {}
@@ -16,9 +16,9 @@ Handler.__index = Handler
1616
---@return render.md.handler.buf.MarkdownInline
1717
function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
19-
self.marks = list.new_marks()
2019
self.config = state.get(buf)
2120
self.context = Context.get(buf)
21+
self.marks = list.new_marks(self.config.anti_conceal.ignore)
2222
self.query = treesitter.parse(
2323
'markdown_inline',
2424
[[

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.3.6'
7+
M.version = '7.3.7'
88

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

lua/render-markdown/init.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,26 @@ local M = {}
174174
---@class (exact) render.md.UserPadding
175175
---@field public highlight? string
176176

177+
---@alias render.md.Element
178+
---| 'head_icon'
179+
---| 'head_background'
180+
---| 'head_border'
181+
---| 'code_language'
182+
---| 'code_background'
183+
---| 'code_border'
184+
---| 'dash'
185+
---| 'bullet'
186+
---| 'check_icon'
187+
---| 'check_scope'
188+
---| 'quote'
189+
---| 'table_border'
190+
---| 'callout'
191+
---| 'link'
192+
---| 'sign'
193+
177194
---@class (exact) render.md.UserAntiConceal
178195
---@field public enabled? boolean
196+
---@field public ignore? table<render.md.Element, boolean>
179197
---@field public above? integer
180198
---@field public below? integer
181199

@@ -262,6 +280,13 @@ M.default_config = {
262280
anti_conceal = {
263281
-- This enables hiding any added text on the line the cursor is on
264282
enabled = true,
283+
-- Which elements to always show, ignoring anti conceal behavior. Possible values are:
284+
-- head_icon, head_background, head_border, code_language, code_background, code_border
285+
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
286+
ignore = {
287+
code_background = true,
288+
sign = true,
289+
},
265290
-- Number of lines above cursor to show
266291
above = 0,
267292
-- Number of lines below cursor to show

lua/render-markdown/render/base.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function Base:sign(text, highlight)
3838
if highlight ~= nil then
3939
sign_highlight = colors.combine(highlight, sign_highlight)
4040
end
41-
self.marks:add(false, self.info.start_row, self.info.start_col, {
41+
self.marks:add('sign', self.info.start_row, self.info.start_col, {
4242
sign_text = text,
4343
sign_hl_group = sign_highlight,
4444
})

lua/render-markdown/render/checkbox.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ end
4646
function Render:icon()
4747
local icon = self.checkbox.icon
4848
local text = self.inline and icon or str.pad_to(self.info.text, icon) .. icon
49-
self.marks:add(true, self.info.start_row, self.info.start_col, {
49+
self.marks:add('check_icon', self.info.start_row, self.info.start_col, {
5050
end_row = self.info.end_row,
5151
end_col = self.info.end_col,
5252
virt_text = { { text, self.checkbox.highlight } },
@@ -65,7 +65,7 @@ function Render:highlight_scope()
6565
if paragraph == nil then
6666
return
6767
end
68-
self.marks:add(true, paragraph.start_row, paragraph.start_col, {
68+
self.marks:add('check_scope', paragraph.start_row, paragraph.start_col, {
6969
end_row = paragraph.end_row,
7070
end_col = paragraph.end_col,
7171
hl_group = highlight,

0 commit comments

Comments
 (0)