Skip to content

Commit 5c0e241

Browse files
chore(refactor): remove top level tables from presets
## Details Storing the top level tables in presets is not necessary given how infrequently we access them (once on each setup). Refactor the presets module to use functions, use local tables within those functions.
1 parent b540997 commit 5c0e241

File tree

3 files changed

+90
-74
lines changed

3 files changed

+90
-74
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 21
1+
*render-markdown.txt* For NVIM v0.11.3 Last change: 2025 July 23
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.7'
8+
M.version = '8.6.8'
99

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

lua/render-markdown/lib/presets.lua

Lines changed: 88 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -11,91 +11,107 @@ 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_preset[user.preset] or {}, {
15-
code = M.code_style[(user.code or {}).style] or {},
16-
pipe_table = vim.tbl_deep_extend(
17-
'force',
18-
M.table_preset[(user.pipe_table or {}).preset] or {},
19-
M.table_style[(user.pipe_table or {}).style] or {}
20-
),
21-
win_options = M.win_options[(user.anti_conceal or {}).enabled] or {},
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),
2218
})
2319
end
2420

2521
---@private
26-
---@type table<render.md.config.Preset?, render.md.UserConfig?>
27-
M.config_preset = {
28-
[Preset.obsidian] = { render_modes = true },
29-
---https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/markdown.lua
30-
[Preset.lazy] = {
31-
file_types = { 'markdown', 'norg', 'rmd', 'org', 'codecompanion' },
32-
code = {
33-
sign = false,
34-
width = 'block',
35-
right_pad = 1,
36-
},
37-
heading = {
38-
sign = false,
39-
icons = {},
40-
},
41-
checkbox = {
42-
enabled = false,
22+
---@param user render.md.UserConfig
23+
---@return render.md.UserConfig
24+
function M.config(user)
25+
---@type table<render.md.config.Preset?, render.md.UserConfig?>
26+
local presets = {
27+
[Preset.obsidian] = { render_modes = true },
28+
---https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/markdown.lua
29+
[Preset.lazy] = {
30+
file_types = { 'markdown', 'norg', 'rmd', 'org', 'codecompanion' },
31+
code = {
32+
sign = false,
33+
width = 'block',
34+
right_pad = 1,
35+
},
36+
heading = {
37+
sign = false,
38+
icons = {},
39+
},
40+
checkbox = {
41+
enabled = false,
42+
},
4343
},
44-
},
45-
}
44+
}
45+
return presets[user.preset] or {}
46+
end
4647

4748
---@private
48-
---@type table<render.md.code.Style?, render.md.code.UserConfig?>
49-
M.code_style = {
50-
['none'] = { enabled = false },
51-
['normal'] = { language = false },
52-
['language'] = { disable_background = true, inline = false },
53-
}
49+
---@param user render.md.UserConfig
50+
---@return render.md.code.UserConfig
51+
function M.code(user)
52+
---@type table<render.md.code.Style?, render.md.code.UserConfig?>
53+
local styles = {
54+
['none'] = { enabled = false },
55+
['normal'] = { language = false },
56+
['language'] = { disable_background = true, inline = false },
57+
}
58+
return styles[(user.code or {}).style] or {}
59+
end
5460

5561
---@private
56-
---@type table<render.md.table.Preset?, render.md.table.UserConfig?>
57-
M.table_preset = {
58-
['round'] = {
59-
-- stylua: ignore
60-
border = {
61-
'', '', '',
62-
'', '', '',
63-
'', '', '',
64-
'', '',
62+
---@param user render.md.UserConfig
63+
---@return render.md.table.UserConfig
64+
function M.pipe_table(user)
65+
---@type table<render.md.table.Preset?, render.md.table.UserConfig?>
66+
local presets = {
67+
['round'] = {
68+
-- stylua: ignore
69+
border = {
70+
'', '', '',
71+
'', '', '',
72+
'', '', '',
73+
'', '',
74+
},
6575
},
66-
},
67-
['double'] = {
68-
-- stylua: ignore
69-
border = {
70-
'', '', '',
71-
'', '', '',
72-
'', '', '',
73-
'', '',
76+
['double'] = {
77+
-- stylua: ignore
78+
border = {
79+
'', '', '',
80+
'', '', '',
81+
'', '', '',
82+
'', '',
83+
},
7484
},
75-
},
76-
['heavy'] = {
77-
alignment_indicator = '',
78-
-- stylua: ignore
79-
border = {
80-
'', '', '',
81-
'', '', '',
82-
'', '', '',
83-
'', '',
85+
['heavy'] = {
86+
alignment_indicator = '',
87+
-- stylua: ignore
88+
border = {
89+
'', '', '',
90+
'', '', '',
91+
'', '', '',
92+
'', '',
93+
},
8494
},
85-
},
86-
}
87-
88-
---@private
89-
---@type table<render.md.table.Style?, render.md.table.UserConfig?>
90-
M.table_style = {
91-
['none'] = { enabled = false },
92-
['normal'] = { border_enabled = false },
93-
}
95+
}
96+
---@type table<render.md.table.Style?, render.md.table.UserConfig?>
97+
local styles = {
98+
['none'] = { enabled = false },
99+
['normal'] = { border_enabled = false },
100+
}
101+
local preset = presets[(user.pipe_table or {}).preset] or {}
102+
local style = styles[(user.pipe_table or {}).style] or {}
103+
return vim.tbl_deep_extend('force', preset, style)
104+
end
94105

95106
---@private
96-
---@type table<boolean?, render.md.window.UserConfigs?>
97-
M.win_options = {
98-
[false] = { concealcursor = { rendered = 'nvic' } },
99-
}
107+
---@param user render.md.UserConfig
108+
---@return render.md.window.UserConfigs
109+
function M.win_options(user)
110+
---@type table<boolean?, render.md.window.UserConfigs?>
111+
local anti_conceals = {
112+
[false] = { concealcursor = { rendered = 'nvic' } },
113+
}
114+
return anti_conceals[(user.anti_conceal or {}).enabled] or {}
115+
end
100116

101117
return M

0 commit comments

Comments
 (0)