Skip to content

Commit 29863dc

Browse files
committedOct 13, 2024
feat: allow anti conceal ignore values to be list of modes
## Details Request: #204 Updates the recently added `anti_conceal.ignore` settings to allow values to be a string list of modes in addition to just booleans. This behaves similarly to the top level `render_modes` setting but at a much more granular, component level. It is also a little confusing parsing all the negatives happening, anti conceal & ignore, what does this mean. When a list of modes is specified these are the modes where the decorations will stick around, i.e. not be hidden when your cursor enters the line. This is similar to neovim's concealcursor behavior.
1 parent c0082b7 commit 29863dc

File tree

12 files changed

+49
-25
lines changed

12 files changed

+49
-25
lines changed
 

Diff for: ‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
[18c7ef7](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/18c7ef71fb4b8d83cb0160adc9127fc4d65ca42e)
1515
- anti conceal per component [#204](https://github.com/MeanderingProgrammer/render-markdown.nvim/issues/204)
1616
[fb6b3d1](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/fb6b3d145e5e12b838c0b84124354802f381b1af)
17+
- align table cells according to indicators [c0082b7](https://github.com/MeanderingProgrammer/render-markdown.nvim/commit/c0082b7d9e33408ba4e451741d8aca2b1f5ed823)
1718

1819
### Bug Fixes
1920

Diff for: ‎README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ 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:
172+
-- Which elements to always show, ignoring anti conceal behavior. Values can either be booleans
173+
-- to fix the behavior or string lists representing modes where anti conceal behavior will be
174+
-- ignored. Possible keys are:
173175
-- head_icon, head_background, head_border, code_language, code_background, code_border
174176
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
175177
ignore = {

Diff for: ‎doc/render-markdown.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,9 @@ 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:
221+
-- Which elements to always show, ignoring anti conceal behavior. Values can either be booleans
222+
-- to fix the behavior or string lists representing modes where anti conceal behavior will be
223+
-- ignored. Possible keys are:
222224
-- head_icon, head_background, head_border, code_language, code_background, code_border
223225
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
224226
ignore = {

Diff for: ‎lua/render-markdown/core/context.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,17 @@ local util = require('render-markdown.core.util')
1313
---@field private conceal? table<integer, [integer, integer][]>
1414
---@field private links table<integer, [integer, integer, integer][]>
1515
---@field private window_width? integer
16+
---@field mode string
1617
---@field last_heading? integer
1718
local Context = {}
1819
Context.__index = Context
1920

2021
---@param buf integer
2122
---@param win integer
23+
---@param mode string
2224
---@param offset integer
2325
---@return render.md.Context
24-
function Context.new(buf, win, offset)
26+
function Context.new(buf, win, mode, offset)
2527
local self = setmetatable({}, Context)
2628
self.buf = buf
2729
self.win = win
@@ -39,6 +41,7 @@ function Context.new(buf, win, offset)
3941
self.conceal = nil
4042
self.links = {}
4143
self.window_width = nil
44+
self.mode = mode
4245
self.last_heading = nil
4346
return self
4447
end
@@ -297,8 +300,9 @@ local M = {}
297300

298301
---@param buf integer
299302
---@param win integer
300-
function M.reset(buf, win)
301-
cache[buf] = Context.new(buf, win, 10)
303+
---@param mode string
304+
function M.reset(buf, win, mode)
305+
cache[buf] = Context.new(buf, win, mode, 10)
302306
end
303307

304308
---@param buf integer

Diff for: ‎lua/render-markdown/core/list.lua

+17-7
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ 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>
5+
---@field private mode string
6+
---@field private ignore render.md.config.conceal.Ignore
67
---@field private marks render.md.Mark[]
78
local Marks = {}
89
Marks.__index = Marks
910

10-
---@param ignore table<render.md.Element, boolean>
11+
---@param mode string
12+
---@param ignore render.md.config.conceal.Ignore
1113
---@return render.md.Marks
12-
function Marks.new(ignore)
14+
function Marks.new(mode, ignore)
1315
local self = setmetatable({}, Marks)
16+
self.mode = mode
1417
self.ignore = ignore
1518
self.marks = {}
1619
return self
@@ -53,18 +56,25 @@ end
5356
function Marks:conceal(element)
5457
if type(element) == 'boolean' then
5558
return element
59+
end
60+
local value = self.ignore[element]
61+
if value == nil then
62+
return true
63+
elseif type(value) == 'boolean' then
64+
return not value
5665
else
57-
return self.ignore[element] ~= true
66+
return not vim.tbl_contains(value, self.mode)
5867
end
5968
end
6069

6170
---@class render.md.ListHelper
6271
local M = {}
6372

64-
---@param ignore? table<render.md.Element, boolean>
73+
---@param mode? string
74+
---@param ignore? render.md.config.conceal.Ignore
6575
---@return render.md.Marks
66-
function M.new_marks(ignore)
67-
return Marks.new(ignore or {})
76+
function M.new_marks(mode, ignore)
77+
return Marks.new(mode or util.mode(), ignore or {})
6878
end
6979

7080
---@generic T

Diff for: ‎lua/render-markdown/core/ui.lua

+4-3
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function M.update(buf, win, parse)
119119
if next_state == 'rendered' then
120120
if not buffer_state:has_marks() or parse then
121121
M.clear(buf, buffer_state)
122-
buffer_state:set_marks(M.parse_buffer(buf, win))
122+
buffer_state:set_marks(M.parse_buffer(buf, win, mode))
123123
end
124124
local hidden = config:hidden(mode, row)
125125
for _, extmark in ipairs(buffer_state:get_marks()) do
@@ -159,15 +159,16 @@ end
159159
---@private
160160
---@param buf integer
161161
---@param win integer
162+
---@param mode string
162163
---@return render.md.Extmark[]
163-
function M.parse_buffer(buf, win)
164+
function M.parse_buffer(buf, win, mode)
164165
local has_parser, parser = pcall(vim.treesitter.get_parser, buf)
165166
if not has_parser then
166167
log.buf('error', 'fail', buf, 'no treesitter parser found')
167168
return {}
168169
end
169170
-- Reset buffer context
170-
Context.reset(buf, win)
171+
Context.reset(buf, win, mode)
171172
-- Make sure injections are processed
172173
Context.get(buf):parse(parser)
173174
-- Parse markdown after all other nodes to take advantage of state

Diff for: ‎lua/render-markdown/handler/markdown.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
1919
self.config = state.get(buf)
2020
self.context = Context.get(buf)
21-
self.marks = list.new_marks(self.config.anti_conceal.ignore)
21+
self.marks = list.new_marks(self.context.mode, self.config.anti_conceal.ignore)
2222
self.query = treesitter.parse(
2323
'markdown',
2424
[[

Diff for: ‎lua/render-markdown/handler/markdown_inline.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function Handler.new(buf)
1818
local self = setmetatable({}, Handler)
1919
self.config = state.get(buf)
2020
self.context = Context.get(buf)
21-
self.marks = list.new_marks(self.config.anti_conceal.ignore)
21+
self.marks = list.new_marks(self.context.mode, self.config.anti_conceal.ignore)
2222
self.query = treesitter.parse(
2323
'markdown_inline',
2424
[[

Diff for: ‎lua/render-markdown/health.lua

+1-1
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.9'
7+
M.version = '7.3.10'
88

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

Diff for: ‎lua/render-markdown/init.lua

+6-2
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,11 @@ local M = {}
192192
---| 'link'
193193
---| 'sign'
194194

195+
---@alias render.md.config.conceal.Ignore table<render.md.Element, string[]|boolean>
196+
195197
---@class (exact) render.md.UserAntiConceal
196198
---@field public enabled? boolean
197-
---@field public ignore? table<render.md.Element, boolean>
199+
---@field public ignore? render.md.config.conceal.Ignore
198200
---@field public above? integer
199201
---@field public below? integer
200202

@@ -281,7 +283,9 @@ M.default_config = {
281283
anti_conceal = {
282284
-- This enables hiding any added text on the line the cursor is on
283285
enabled = true,
284-
-- Which elements to always show, ignoring anti conceal behavior. Possible values are:
286+
-- Which elements to always show, ignoring anti conceal behavior. Values can either be booleans
287+
-- to fix the behavior or string lists representing modes where anti conceal behavior will be
288+
-- ignored. Possible keys are:
285289
-- head_icon, head_background, head_border, code_language, code_background, code_border
286290
-- dash, bullet, check_icon, check_scope, quote, table_border, callout, link, sign
287291
ignore = {

Diff for: ‎lua/render-markdown/state.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,10 @@ function M.validate()
142142
:type('ignore', 'table')
143143
:check()
144144
get_spec({ 'anti_conceal', 'ignore' })
145-
:type({ 'head_icon', 'head_background', 'head_border' }, { 'boolean', 'nil' })
146-
:type({ 'code_language', 'code_background', 'code_border' }, { 'boolean', 'nil' })
147-
:type({ 'dash', 'bullet', 'check_icon', 'check_scope' }, { 'boolean', 'nil' })
148-
:type({ 'quote', 'table_border', 'callout', 'link', 'sign' }, { 'boolean', 'nil' })
145+
:list({ 'head_icon', 'head_background', 'head_border' }, 'string', { 'boolean', 'nil' })
146+
:list({ 'code_language', 'code_background', 'code_border' }, 'string', { 'boolean', 'nil' })
147+
:list({ 'dash', 'bullet', 'check_icon', 'check_scope' }, 'string', { 'boolean', 'nil' })
148+
:list({ 'quote', 'table_border', 'callout', 'link', 'sign' }, 'string', { 'boolean', 'nil' })
149149
:check()
150150

151151
get_spec('padding'):type('highlight', 'string'):check()

Diff for: ‎lua/render-markdown/types.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150

151151
---@class (exact) render.md.AntiConceal
152152
---@field public enabled boolean
153-
---@field public ignore table<render.md.Element, boolean>
153+
---@field public ignore render.md.config.conceal.Ignore
154154
---@field public above integer
155155
---@field public below integer
156156

0 commit comments

Comments
 (0)
Please sign in to comment.