Skip to content

Commit 9a8a2e5

Browse files
feat!: Support full buftype options
## Details Adds support for an `overrides` field that allows for essentially a full configuration per buftype. If no configuration is specified for a particular buftype or a partial configuration the logic falls back to the top level configuration. The top level configuration can be viewed as the default and then overrides change it for specific buffers. Because this mechanism is much more powerful it deprecates all other buftype options as they can now be accomplished via this new mechanism. The equivalents are as follows: - `exclude.buftypes.<value>` -> `overrides.buftype.<value>.enabled = false` - `sign.exclude.buftypes.<value>` -> `overrides.buftype.<value>.sign.enabled = false` The previous default behavior of not showing signs on LSP floating docs has been ported over, so anyone using default configurations should not experience any problems. Since the configuration is accessed all through the codebase there is a pretty large code change here, but a lot if it is passing the new resolved configuration around. This enables a feature like different code padding by default vs. in LSP floating windows with: ```lua require('render-markdown').setup({ code = { left_pad = 4 }, overrides = { buftype = { nofile = { code = { left_pad = 0 }, }, }, }, }) ```
1 parent dcfa033 commit 9a8a2e5

File tree

18 files changed

+570
-381
lines changed

18 files changed

+570
-381
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
interchangeable. Notice of deprecation has been available for a month since
1010
[726c85c](https://github.com/MeanderingProgrammer/markdown.nvim/commit/726c85cb9cc6d7d9c85af6ab093e1ee53b5e3c82).
1111
- Ultimately removed in TODO
12-
- Remove `profile` field in favor of benches [2f21726](https://github.com/MeanderingProgrammer/markdown.nvim/commit/2f217266c6b416c4948ddb7e88a5db02670c75d5)
12+
- Remove `profile` field in favor of benches [dcfa033](https://github.com/MeanderingProgrammer/markdown.nvim/commit/dcfa033cb39bc4f30019925aa91d3af5ec049614)
1313
- In order to fix:
1414
- Implement `parse` method instead of `render`, no direct translation
1515
- `profile` field was only meant for development, should not have any users

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,6 @@ require('render-markdown').setup({
180180
render_modes = { 'n', 'c' },
181181
-- Set to avoid seeing warnings for conflicts in health check
182182
acknowledge_conflicts = false,
183-
exclude = {
184-
-- Buftypes ignored by this plugin, see :h 'buftype'
185-
buftypes = {},
186-
},
187183
anti_conceal = {
188184
-- This enables hiding any added text on the line the cursor is on
189185
-- This does have a performance penalty as we must listen to the 'CursorMoved' event
@@ -399,10 +395,6 @@ require('render-markdown').setup({
399395
sign = {
400396
-- Turn on / off sign rendering
401397
enabled = true,
402-
-- More granular mechanism, disable signs within specific buftypes
403-
exclude = {
404-
buftypes = { 'nofile' },
405-
},
406398
-- Applies to background of sign text
407399
highlight = 'RenderMarkdownSign',
408400
},
@@ -423,6 +415,19 @@ require('render-markdown').setup({
423415
rendered = '',
424416
},
425417
},
418+
-- More granular configuration mechanism, allows different aspects of buffers
419+
-- to have their own behavior. Values default to the top level configuration
420+
-- if no override is provided. Supports the following fields:
421+
-- enabled, max_file_size, render_modes, anti_conceal, heading, code, dash, bullet,
422+
-- checkbox, quote, pipe_table, callout, link, sign, win_options
423+
overrides = {
424+
-- Overrides for different buftypes, see :h 'buftype'
425+
buftype = {
426+
nofile = {
427+
sign = { enabled = false },
428+
},
429+
},
430+
},
426431
-- Mapping from treesitter language to user defined handlers
427432
-- See 'Custom Handlers' document for more info
428433
custom_handlers = {},
@@ -703,10 +708,6 @@ require('render-markdown').setup({
703708
sign = {
704709
-- Turn on / off sign rendering
705710
enabled = true,
706-
-- More granular mechanism, disable signs within specific buftypes
707-
exclude = {
708-
buftypes = { 'nofile' },
709-
},
710711
-- Applies to background of sign text
711712
highlight = 'RenderMarkdownSign',
712713
},

doc/custom-handlers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ needed, and concealing when the cursor enters.
1212
Each handler must conform to the following interface:
1313

1414
```lua
15-
---@class render.md.Mark
15+
---@class (exact) render.md.Mark
1616
---@field public conceal boolean
1717
---@field public start_row integer
1818
---@field public start_col integer
1919
---@field public opts vim.api.keyset.set_extmark
2020

21-
---@class render.md.Handler
21+
---@class (exact) render.md.Handler
2222
---@field public parse fun(root: TSNode, buf: integer): render.md.Mark[]
2323
---@field public extends? boolean
2424
```

doc/render-markdown.txt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,6 @@ Full Default Configuration ~
212212
render_modes = { 'n', 'c' },
213213
-- Set to avoid seeing warnings for conflicts in health check
214214
acknowledge_conflicts = false,
215-
exclude = {
216-
-- Buftypes ignored by this plugin, see :h 'buftype'
217-
buftypes = {},
218-
},
219215
anti_conceal = {
220216
-- This enables hiding any added text on the line the cursor is on
221217
-- This does have a performance penalty as we must listen to the 'CursorMoved' event
@@ -431,10 +427,6 @@ Full Default Configuration ~
431427
sign = {
432428
-- Turn on / off sign rendering
433429
enabled = true,
434-
-- More granular mechanism, disable signs within specific buftypes
435-
exclude = {
436-
buftypes = { 'nofile' },
437-
},
438430
-- Applies to background of sign text
439431
highlight = 'RenderMarkdownSign',
440432
},
@@ -455,6 +447,19 @@ Full Default Configuration ~
455447
rendered = '',
456448
},
457449
},
450+
-- More granular configuration mechanism, allows different aspects of buffers
451+
-- to have their own behavior. Values default to the top level configuration
452+
-- if no override is provided. Supports the following fields:
453+
-- enabled, max_file_size, render_modes, anti_conceal, heading, code, dash, bullet,
454+
-- checkbox, quote, pipe_table, callout, link, sign, win_options
455+
overrides = {
456+
-- Overrides for different buftypes, see :h 'buftype'
457+
buftype = {
458+
nofile = {
459+
sign = { enabled = false },
460+
},
461+
},
462+
},
458463
-- Mapping from treesitter language to user defined handlers
459464
-- See 'Custom Handlers' document for more info
460465
custom_handlers = {},
@@ -743,10 +748,6 @@ SIGNS *render-markdown-setup-signs*
743748
sign = {
744749
-- Turn on / off sign rendering
745750
enabled = true,
746-
-- More granular mechanism, disable signs within specific buftypes
747-
exclude = {
748-
buftypes = { 'nofile' },
749-
},
750751
-- Applies to background of sign text
751752
highlight = 'RenderMarkdownSign',
752753
},

lua/render-markdown/component.lua

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
local state = require('render-markdown.state')
2-
31
---@class render.md.Component
42
---@field text string
53
---@field highlight string
64

75
---@class render.md.ComponentHelper
86
local M = {}
97

8+
---@param config render.md.BufferConfig
109
---@param text string
1110
---@param comparison 'exact'|'contains'
1211
---@return render.md.Component?
13-
function M.callout(text, comparison)
12+
function M.callout(config, text, comparison)
1413
---@param callout render.md.CustomComponent
1514
---@return boolean
1615
local function matches(callout)
@@ -22,18 +21,19 @@ function M.callout(text, comparison)
2221
error(string.format('Unhandled comparison: %s', comparison))
2322
end
2423
end
25-
for _, callout in pairs(state.config.callout) do
24+
for _, callout in pairs(config.callout) do
2625
if matches(callout) then
2726
return { text = callout.rendered, highlight = callout.highlight }
2827
end
2928
end
3029
return nil
3130
end
3231

32+
---@param config render.md.BufferConfig
3333
---@param text string
3434
---@param comparison 'exact'|'starts'
3535
---@return render.md.Component?
36-
function M.checkbox(text, comparison)
36+
function M.checkbox(config, text, comparison)
3737
---@param checkbox render.md.CustomComponent
3838
---@return boolean
3939
local function matches(checkbox)
@@ -45,7 +45,7 @@ function M.checkbox(text, comparison)
4545
error(string.format('Unhandled comparison: %s', comparison))
4646
end
4747
end
48-
for _, checkbox in pairs(state.config.checkbox.custom) do
48+
for _, checkbox in pairs(config.checkbox.custom) do
4949
if matches(checkbox) then
5050
return { text = checkbox.rendered, highlight = checkbox.highlight }
5151
end

lua/render-markdown/handler/latex.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ local M = {}
1515
---@param buf integer
1616
---@return render.md.Mark[]
1717
function M.parse(root, buf)
18-
local latex = state.config.latex
18+
local latex = state.latex
1919
if not latex.enabled then
2020
return {}
2121
end

0 commit comments

Comments
 (0)