Skip to content

Commit eec00fb

Browse files
fix: resolve styles & presets in overrides
## Details After changing how styles are handled I neglected to handle values placed inside of overrides. This meant that they would effectively be ignored as they do not modify the concrete values. To fix this loop over overrides and resolve them as part of the logic of the `presets` module.
1 parent 9e51b77 commit eec00fb

File tree

4 files changed

+102
-9
lines changed

4 files changed

+102
-9
lines changed

doc/render-markdown.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 28
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 31
22

33
==============================================================================
44
Table of Contents *render-markdown-table-of-contents*

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

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

lua/render-markdown/lib/presets.lua

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ local M = {}
1111
---@param user render.md.UserConfig
1212
---@return render.md.UserConfig
1313
function M.get(user)
14-
return vim.tbl_deep_extend('force', M.config(user), {
15-
code = M.code(user),
16-
pipe_table = M.pipe_table(user),
17-
win_options = M.win_options(user),
18-
})
14+
return vim.tbl_deep_extend(
15+
'force',
16+
M.config(user),
17+
M.partial(user),
18+
M.overrides(user)
19+
)
1920
end
2021

2122
---@private
@@ -45,8 +46,41 @@ function M.config(user)
4546
return presets[user.preset] or {}
4647
end
4748

49+
---@private
50+
---@param user render.md.partial.UserConfig
51+
---@return render.md.partial.UserConfig
52+
function M.partial(user)
53+
---@type render.md.partial.UserConfig
54+
return {
55+
code = M.code(user),
56+
pipe_table = M.pipe_table(user),
57+
win_options = M.win_options(user),
58+
}
59+
end
60+
4861
---@private
4962
---@param user render.md.UserConfig
63+
---@return render.md.UserConfig
64+
function M.overrides(user)
65+
local configs = {} ---@type render.md.overrides.UserConfig
66+
for _, name in ipairs({ 'buflisted', 'buftype', 'filetype' }) do
67+
local overrides = (user.overrides or {})[name] ---@type table<any, render.md.partial.UserConfig>?
68+
if type(overrides) == 'table' then
69+
local config = {} ---@type table<any, render.md.partial.UserConfig>
70+
for value, override in pairs(overrides) do
71+
if type(override) == 'table' then
72+
config[value] = M.partial(override)
73+
end
74+
end
75+
configs[name] = config
76+
end
77+
end
78+
---@type render.md.UserConfig
79+
return { overrides = configs }
80+
end
81+
82+
---@private
83+
---@param user render.md.partial.UserConfig
5084
---@return render.md.code.UserConfig
5185
function M.code(user)
5286
---@type table<render.md.code.Style?, render.md.code.UserConfig?>
@@ -59,7 +93,7 @@ function M.code(user)
5993
end
6094

6195
---@private
62-
---@param user render.md.UserConfig
96+
---@param user render.md.partial.UserConfig
6397
---@return render.md.table.UserConfig
6498
function M.pipe_table(user)
6599
---@type table<render.md.table.Preset?, render.md.table.UserConfig?>
@@ -104,7 +138,7 @@ function M.pipe_table(user)
104138
end
105139

106140
---@private
107-
---@param user render.md.UserConfig
141+
---@param user render.md.partial.UserConfig
108142
---@return render.md.window.UserConfigs
109143
function M.win_options(user)
110144
---@type table<boolean?, render.md.window.UserConfigs?>

tests/presets_spec.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---@module 'luassert'
2+
3+
---@param user render.md.UserConfig
4+
---@param expected render.md.UserConfig
5+
local function validate(user, expected)
6+
local actual = require('render-markdown.lib.presets').get(user)
7+
assert.same(expected, actual)
8+
end
9+
10+
describe('presets', function()
11+
it('overlap', function()
12+
validate({
13+
preset = 'lazy',
14+
code = { style = 'normal' },
15+
}, {
16+
file_types = { 'markdown', 'norg', 'rmd', 'org', 'codecompanion' },
17+
code = {
18+
sign = false,
19+
width = 'block',
20+
right_pad = 1,
21+
language = false,
22+
},
23+
heading = {
24+
sign = false,
25+
icons = {},
26+
},
27+
checkbox = { enabled = false },
28+
pipe_table = {},
29+
win_options = {},
30+
overrides = {},
31+
})
32+
end)
33+
34+
it('override', function()
35+
validate({
36+
code = { style = 'none' },
37+
overrides = {
38+
buftype = {
39+
nofile = {
40+
code = { style = 'normal' },
41+
},
42+
},
43+
},
44+
}, {
45+
code = { enabled = false },
46+
pipe_table = {},
47+
win_options = {},
48+
overrides = {
49+
buftype = {
50+
nofile = {
51+
code = { language = false },
52+
pipe_table = {},
53+
win_options = {},
54+
},
55+
},
56+
},
57+
})
58+
end)
59+
end)

0 commit comments

Comments
 (0)