Skip to content

Commit 05e6a6d

Browse files
feat: ignore option, checked before attaching
## Details Adds top level `ignore` configuration option. This option should be a function which accepts a buffer id as input and returns a boolean of whether to ignore the buffer or not. Default value returns `false` for all buffers to keep behavior unchanged. This runs after the filetype & max file size checks. Users should use this if they want to be more clever about the kinds of buffers this plugin ignores, where the filetype, size, & option approaches are not enough. For instance you could use to check if a certain variable is set on the buffer using `vim.api.nvim_buf_get_var` and ignore buffers that specify certain variables. At the time of attaching to a buffer it may not necessarily be associated with a `window`, and even if it were this `window` can change over time, so the function is not provided with a `window` id as part of its input. Instead if users want to use the window of a `buffer` to decide they'll need to do something like `local win = vim.fn.bufwinid(buf)`. Minor other refactors: - Update validator to not return self - Name the local configs in renderers info
1 parent d7462eb commit 05e6a6d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+462
-468
lines changed

Diff for: README.md

+4
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ require('render-markdown').setup({
204204
log_runtime = false,
205205
-- Filetypes this plugin will run on.
206206
file_types = { 'markdown' },
207+
-- Takes buffer as input, if it returns true this plugin will not attach to the buffer
208+
ignore = function()
209+
return false
210+
end,
207211
-- Additional events that will trigger this plugin's render loop.
208212
change_events = {},
209213
-- Out of the box language injections for known filetypes that allow markdown to be interpreted

Diff for: doc/render-markdown.txt

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For 0.11.0 Last change: 2025 April 07
1+
*render-markdown.txt* For 0.11.0 Last change: 2025 April 08
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*
@@ -269,6 +269,10 @@ Default Configuration ~
269269
log_runtime = false,
270270
-- Filetypes this plugin will run on.
271271
file_types = { 'markdown' },
272+
-- Takes buffer as input, if it returns true this plugin will not attach to the buffer
273+
ignore = function()
274+
return false
275+
end,
272276
-- Additional events that will trigger this plugin's render loop.
273277
change_events = {},
274278
-- Out of the box language injections for known filetypes that allow markdown to be interpreted

Diff for: lua/render-markdown/api.lua

+10-6
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ function M.buf_toggle()
3030
end
3131

3232
function M.log()
33-
require('render-markdown.core.log').open()
33+
local log = require('render-markdown.core.log')
34+
log.open()
3435
end
3536

3637
function M.expand()
@@ -44,14 +45,17 @@ function M.contract()
4445
end
4546

4647
function M.debug()
47-
local buf, win = Env.buf.current(), Env.win.current()
48-
local row, marks =
49-
require('render-markdown.core.ui').get_row_marks(buf, win)
50-
require('render-markdown.debug.marks').debug(row, marks)
48+
local ui = require('render-markdown.core.ui')
49+
local disply = require('render-markdown.debug.marks')
50+
local buf = Env.buf.current()
51+
local win = Env.win.current()
52+
local row, marks = ui.get_row_marks(buf, win)
53+
disply.show(row, marks)
5154
end
5255

5356
function M.config()
54-
local difference = state.difference(require('render-markdown').default)
57+
local markdown = require('render-markdown')
58+
local difference = state.difference(markdown.default)
5559
if vim.tbl_count(difference) == 0 then
5660
vim.print('Default Configuration')
5761
else

Diff for: lua/render-markdown/command.lua

+5-6
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,19 @@ end
2929
---@private
3030
---@param opts { fargs: string[] }
3131
function M.command(opts)
32-
local args, message = opts.fargs, nil
32+
local args, err = opts.fargs, nil
3333
if #args == 0 or #args == 1 then
3434
local command = #args == 0 and api.enable or api[args[1]]
3535
if command ~= nil then
3636
command()
3737
else
38-
message = string.format('unexpected command: %s', args[1])
38+
err = string.format('unexpected command: %s', args[1])
3939
end
4040
else
41-
message = string.format('unexpected # arguments: %d', #args)
41+
err = string.format('unexpected # arguments: %d', #args)
4242
end
43-
if message ~= nil then
44-
local notification = string.format('%s: %s', M.plugin, message)
45-
vim.notify(notification, vim.log.levels.ERROR)
43+
if err ~= nil then
44+
vim.notify(string.format('%s: %s', M.plugin, err), vim.log.levels.ERROR)
4645
end
4746
end
4847

Diff for: lua/render-markdown/config.lua

+20-36
Original file line numberDiff line numberDiff line change
@@ -37,44 +37,28 @@ function Config.new(config)
3737
end
3838

3939
---@param spec render.md.debug.ValidatorSpec
40-
---@return render.md.debug.ValidatorSpec
4140
function Config.validate(spec)
4241
require('render-markdown.config.base').validate(spec)
43-
return spec:type('max_file_size', 'number')
44-
:type('debounce', 'number')
45-
:nested(
46-
'anti_conceal',
47-
require('render-markdown.config.anti_conceal').validate
48-
)
49-
:nested('bullet', require('render-markdown.config.bullet').validate)
50-
:nested('callout', require('render-markdown.config.callout').validate)
51-
:nested('checkbox', require('render-markdown.config.checkbox').validate)
52-
:nested('code', require('render-markdown.config.code').validate)
53-
:nested('dash', require('render-markdown.config.dash').validate)
54-
:nested('heading', require('render-markdown.config.heading').validate)
55-
:nested('html', require('render-markdown.config.html').validate)
56-
:nested('indent', require('render-markdown.config.indent').validate)
57-
:nested(
58-
'inline_highlight',
59-
require('render-markdown.config.inline_highlight').validate
60-
)
61-
:nested('latex', require('render-markdown.config.latex').validate)
62-
:nested('link', require('render-markdown.config.link').validate)
63-
:nested('padding', require('render-markdown.config.padding').validate)
64-
:nested(
65-
'paragraph',
66-
require('render-markdown.config.paragraph').validate
67-
)
68-
:nested(
69-
'pipe_table',
70-
require('render-markdown.config.pipe_table').validate
71-
)
72-
:nested('quote', require('render-markdown.config.quote').validate)
73-
:nested('sign', require('render-markdown.config.sign').validate)
74-
:nested(
75-
'win_options',
76-
require('render-markdown.config.win_options').validate
77-
)
42+
spec:type('max_file_size', 'number')
43+
spec:type('debounce', 'number')
44+
spec:config('anti_conceal')
45+
spec:config('bullet')
46+
spec:config('callout')
47+
spec:config('checkbox')
48+
spec:config('code')
49+
spec:config('dash')
50+
spec:config('heading')
51+
spec:config('html')
52+
spec:config('indent')
53+
spec:config('inline_highlight')
54+
spec:config('latex')
55+
spec:config('link')
56+
spec:config('padding')
57+
spec:config('paragraph')
58+
spec:config('pipe_table')
59+
spec:config('quote')
60+
spec:config('sign')
61+
spec:config('win_options')
7862
end
7963

8064
---@private

Diff for: lua/render-markdown/config/anti_conceal.lua

+10-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
---@alias render.md.conceal.Ignore table<render.md.Element, render.md.Modes>
88

99
---@enum (key) render.md.Element
10-
local element = {
10+
local Element = {
1111
head_icon = 'head_icon',
1212
head_background = 'head_background',
1313
head_border = 'head_border',
@@ -30,14 +30,15 @@ local M = {}
3030
---@param spec render.md.debug.ValidatorSpec
3131
function M.validate(spec)
3232
spec:type('enabled', 'boolean')
33-
:nested('ignore', function(ignore)
34-
ignore
35-
:list(vim.tbl_keys(element), 'string', { 'boolean', 'nil' })
36-
:check()
37-
end)
38-
:type('above', 'number')
39-
:type('below', 'number')
40-
:check()
33+
spec:nested('ignore', function(ignore)
34+
for element in pairs(Element) do
35+
ignore:list(element, 'string', { 'boolean', 'nil' })
36+
end
37+
ignore:check()
38+
end)
39+
spec:type('above', 'number')
40+
spec:type('below', 'number')
41+
spec:check()
4142
end
4243

4344
return M

Diff for: lua/render-markdown/config/base.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ local M = {}
88

99
---@param spec render.md.debug.ValidatorSpec
1010
function M.validate(spec)
11-
spec:type('enabled', 'boolean'):list('render_modes', 'string', 'boolean')
11+
spec:type('enabled', 'boolean')
12+
spec:list('render_modes', 'string', 'boolean')
1213
end
1314

1415
return M

Diff for: lua/render-markdown/config/bullet.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ local M = {}
2727
function M.validate(spec)
2828
require('render-markdown.config.base').validate(spec)
2929
spec:nested_list('icons', 'string', 'function')
30-
:nested_list('ordered_icons', 'string', 'function')
31-
:type('left_pad', { 'number', 'function' })
32-
:type('right_pad', { 'number', 'function' })
33-
:nested_list('highlight', 'string', 'function')
34-
:nested_list('scope_highlight', 'string', 'function')
35-
:check()
30+
spec:nested_list('ordered_icons', 'string', 'function')
31+
spec:type('left_pad', { 'number', 'function' })
32+
spec:type('right_pad', { 'number', 'function' })
33+
spec:nested_list('highlight', 'string', 'function')
34+
spec:nested_list('scope_highlight', 'string', 'function')
35+
spec:check()
3636
end
3737

3838
return M

Diff for: lua/render-markdown/config/callout.lua

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ local M = {}
1010
---@param spec render.md.debug.ValidatorSpec
1111
function M.validate(spec)
1212
spec:each(function(callout)
13-
callout
14-
:type('raw', 'string')
15-
:type('rendered', 'string')
16-
:type('highlight', 'string')
17-
:type('quote_icon', { 'string', 'nil' })
18-
:type('category', { 'string', 'nil' })
19-
:check()
20-
end, false):check()
13+
callout:type('raw', 'string')
14+
callout:type('rendered', 'string')
15+
callout:type('highlight', 'string')
16+
callout:type('quote_icon', { 'string', 'nil' })
17+
callout:type('category', { 'string', 'nil' })
18+
callout:check()
19+
end, false)
20+
spec:check()
2121
end
2222

2323
return M

Diff for: lua/render-markdown/config/checkbox.lua

+16-15
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,23 @@ local M = {}
2121
function M.validate(spec)
2222
require('render-markdown.config.base').validate(spec)
2323
spec:type('right_pad', 'number')
24-
:nested({ 'unchecked', 'checked' }, function(box)
25-
box:type('icon', 'string')
26-
:type('highlight', 'string')
27-
:type('scope_highlight', { 'string', 'nil' })
28-
:check()
24+
spec:nested({ 'unchecked', 'checked' }, function(box)
25+
box:type('icon', 'string')
26+
box:type('highlight', 'string')
27+
box:type('scope_highlight', { 'string', 'nil' })
28+
box:check()
29+
end)
30+
spec:nested('custom', function(boxes)
31+
boxes:each(function(box)
32+
box:type('raw', 'string')
33+
box:type('rendered', 'string')
34+
box:type('highlight', 'string')
35+
box:type('scope_highlight', { 'string', 'nil' })
36+
box:check()
2937
end)
30-
:nested('custom', function(boxes)
31-
boxes:each(function(box)
32-
box:type('raw', 'string')
33-
:type('rendered', 'string')
34-
:type('highlight', 'string')
35-
:type('scope_highlight', { 'string', 'nil' })
36-
:check()
37-
end)
38-
end)
39-
:check()
38+
boxes:check()
39+
end)
40+
spec:check()
4041
end
4142

4243
return M

Diff for: lua/render-markdown/config/code.lua

+23-23
Original file line numberDiff line numberDiff line change
@@ -57,29 +57,29 @@ local M = {}
5757
function M.validate(spec)
5858
require('render-markdown.config.base').validate(spec)
5959
spec:type('sign', 'boolean')
60-
:one_of('style', vim.tbl_keys(Style))
61-
:one_of('position', vim.tbl_keys(Position))
62-
:type('language_pad', 'number')
63-
:type('language_icon', 'boolean')
64-
:type('language_name', 'boolean')
65-
:list('disable_background', 'string', 'boolean')
66-
:one_of('width', vim.tbl_keys(Width))
67-
:type('left_margin', 'number')
68-
:type('left_pad', 'number')
69-
:type('right_pad', 'number')
70-
:type('min_width', 'number')
71-
:one_of('border', vim.tbl_keys(Border))
72-
:type('above', 'string')
73-
:type('below', 'string')
74-
:type('inline_left', 'string')
75-
:type('inline_right', 'string')
76-
:type('inline_pad', 'number')
77-
:type('highlight', 'string')
78-
:type('highlight_language', { 'string', 'nil' })
79-
:type('highlight_border', { 'string', 'boolean' })
80-
:type('highlight_fallback', 'string')
81-
:type('highlight_inline', 'string')
82-
:check()
60+
spec:one_of('style', vim.tbl_keys(Style))
61+
spec:one_of('position', vim.tbl_keys(Position))
62+
spec:type('language_pad', 'number')
63+
spec:type('language_icon', 'boolean')
64+
spec:type('language_name', 'boolean')
65+
spec:list('disable_background', 'string', 'boolean')
66+
spec:one_of('width', vim.tbl_keys(Width))
67+
spec:type('left_margin', 'number')
68+
spec:type('left_pad', 'number')
69+
spec:type('right_pad', 'number')
70+
spec:type('min_width', 'number')
71+
spec:one_of('border', vim.tbl_keys(Border))
72+
spec:type('above', 'string')
73+
spec:type('below', 'string')
74+
spec:type('inline_left', 'string')
75+
spec:type('inline_right', 'string')
76+
spec:type('inline_pad', 'number')
77+
spec:type('highlight', 'string')
78+
spec:type('highlight_language', { 'string', 'nil' })
79+
spec:type('highlight_border', { 'string', 'boolean' })
80+
spec:type('highlight_fallback', 'string')
81+
spec:type('highlight_inline', 'string')
82+
spec:check()
8383
end
8484

8585
return M

Diff for: lua/render-markdown/config/completions.lua

+5-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ local M = {}
1616
---@param spec render.md.debug.ValidatorSpec
1717
function M.validate(spec)
1818
spec:nested({ 'blink', 'coq', 'lsp' }, function(completion)
19-
completion:type('enabled', 'boolean'):check()
19+
completion:type('enabled', 'boolean')
20+
completion:check()
2021
end)
2122
spec:nested('filter', function(filter)
22-
filter:type('callout', 'function'):type('checkbox', 'function'):check()
23+
filter:type('callout', 'function')
24+
filter:type('checkbox', 'function')
25+
filter:check()
2326
end)
2427
spec:check()
2528
end

Diff for: lua/render-markdown/config/dash.lua

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ local M = {}
1010
function M.validate(spec)
1111
require('render-markdown.config.base').validate(spec)
1212
spec:type('icon', 'string')
13-
:one_of('width', { 'full' }, 'number')
14-
:type('left_margin', 'number')
15-
:type('highlight', 'string')
16-
:check()
13+
spec:one_of('width', { 'full' }, 'number')
14+
spec:type('left_margin', 'number')
15+
spec:type('highlight', 'string')
16+
spec:check()
1717
end
1818

1919
return M

0 commit comments

Comments
 (0)