1
- local components = require (' render-markdown.components ' )
1
+ local Config = require (' render-markdown.config ' )
2
2
local log = require (' render-markdown.core.log' )
3
3
local presets = require (' render-markdown.presets' )
4
4
local treesitter = require (' render-markdown.core.treesitter' )
@@ -78,7 +78,7 @@ function M.get_config(buf)
78
78
buf_config = vim .tbl_deep_extend (' force' , buf_config , override )
79
79
end
80
80
end
81
- config = components . resolve (buf_config )
81
+ config = Config . new (buf_config )
82
82
configs [buf ] = config
83
83
end
84
84
return config
@@ -113,45 +113,49 @@ end
113
113
114
114
--- @return string[]
115
115
function M .validate ()
116
- local errors = {}
116
+ --- @param types type[]
117
+ --- @param nilable boolean
118
+ --- @return string
119
+ local function handle_types (types , nilable )
120
+ if nilable then
121
+ table.insert (types , ' nil' )
122
+ end
123
+ return # types == 0 and ' ' or (' or type ' .. vim .inspect (types ))
124
+ end
117
125
118
126
--- @param value any
119
- --- @param valid_values string[]
120
- --- @param valid_types type[]
127
+ --- @param values string[]
128
+ --- @param types type[]
121
129
--- @param nilable boolean
122
130
--- @return vim.validate.Spec
123
- local function one_of (value , valid_values , valid_types , nilable )
124
- if nilable then
125
- table.insert (valid_types , ' nil' )
126
- end
131
+ local function one_of (value , values , types , nilable )
132
+ local suffix = handle_types (types , nilable )
127
133
return {
128
134
value ,
129
135
function (v )
130
- return vim .tbl_contains (valid_values , v ) or vim .tbl_contains (valid_types , type (v ))
136
+ return vim .tbl_contains (values , v ) or vim .tbl_contains (types , type (v ))
131
137
end ,
132
- ' one of ' .. vim .inspect (valid_values ) .. ' or type ' .. vim . inspect ( valid_types ) ,
138
+ ' one of ' .. vim .inspect (values ) .. suffix ,
133
139
}
134
140
end
135
141
136
142
--- @param value any
137
- --- @param valid_values string[]
143
+ --- @param values string[]
144
+ --- @param types type[]
138
145
--- @param nilable boolean
139
146
--- @return vim.validate.Spec
140
- local function one_or_array_of (value , valid_values , nilable )
141
- local description = ' one or array of ' .. vim .inspect (valid_values )
142
- if nilable then
143
- description = description .. ' or nil'
144
- end
147
+ local function one_or_array_of (value , values , types , nilable )
148
+ local suffix = handle_types (types , nilable )
145
149
return {
146
150
value ,
147
151
function (v )
148
- if v == nil then
149
- return nilable
152
+ if vim . tbl_contains ( types , type ( v )) then
153
+ return true
150
154
elseif type (v ) == ' string' then
151
- return vim .tbl_contains (valid_values , v )
155
+ return vim .tbl_contains (values , v )
152
156
elseif type (v ) == ' table' then
153
157
for i , item in ipairs (v ) do
154
- if not vim .tbl_contains (valid_values , item ) then
158
+ if not vim .tbl_contains (values , item ) then
155
159
return false , string.format (' Index %d is %s' , i , item )
156
160
end
157
161
end
@@ -160,23 +164,21 @@ function M.validate()
160
164
return false
161
165
end
162
166
end ,
163
- description ,
167
+ ' one or array of ' .. vim . inspect ( values ) .. suffix ,
164
168
}
165
169
end
166
170
167
- --- @param value string[]
171
+ --- @param value any
172
+ --- @param types type[]
168
173
--- @param nilable boolean
169
174
--- @return vim.validate.Spec
170
- local function string_array (value , nilable )
171
- local description = ' string array'
172
- if nilable then
173
- description = description .. ' or nil'
174
- end
175
+ local function string_array (value , types , nilable )
176
+ local suffix = handle_types (types , nilable )
175
177
return {
176
178
value ,
177
179
function (v )
178
- if v == nil then
179
- return nilable
180
+ if vim . tbl_contains ( types , type ( v )) then
181
+ return true
180
182
elseif type (v ) == ' table' then
181
183
for i , item in ipairs (v ) do
182
184
if type (item ) ~= ' string' then
@@ -188,10 +190,12 @@ function M.validate()
188
190
return false
189
191
end
190
192
end ,
191
- description ,
193
+ ' string array ' .. suffix ,
192
194
}
193
195
end
194
196
197
+ local errors = {}
198
+
195
199
--- @param suffix string
196
200
--- @param input table<string , any>
197
201
--- @param opts table<string , vim.validate.Spec>
@@ -227,18 +231,18 @@ function M.validate()
227
231
enabled = { heading .enabled , ' boolean' , nilable },
228
232
sign = { heading .sign , ' boolean' , nilable },
229
233
position = one_of (heading .position , { ' overlay' , ' inline' }, {}, nilable ),
230
- icons = string_array (heading .icons , nilable ),
231
- signs = string_array (heading .signs , nilable ),
232
- width = one_or_array_of (heading .width , { ' full' , ' block' }, nilable ),
234
+ icons = string_array (heading .icons , {}, nilable ),
235
+ signs = string_array (heading .signs , {}, nilable ),
236
+ width = one_or_array_of (heading .width , { ' full' , ' block' }, {}, nilable ),
233
237
left_pad = { heading .left_pad , ' number' , nilable },
234
238
right_pad = { heading .right_pad , ' number' , nilable },
235
239
min_width = { heading .min_width , ' number' , nilable },
236
240
border = { heading .border , ' boolean' , nilable },
237
241
border_prefix = { heading .border_prefix , ' boolean' , nilable },
238
242
above = { heading .above , ' string' , nilable },
239
243
below = { heading .below , ' string' , nilable },
240
- backgrounds = string_array (heading .backgrounds , nilable ),
241
- foregrounds = string_array (heading .foregrounds , nilable ),
244
+ backgrounds = string_array (heading .backgrounds , {}, nilable ),
245
+ foregrounds = string_array (heading .foregrounds , {}, nilable ),
242
246
})
243
247
end
244
248
@@ -250,7 +254,7 @@ function M.validate()
250
254
style = one_of (code .style , { ' full' , ' normal' , ' language' , ' none' }, {}, nilable ),
251
255
position = one_of (code .position , { ' left' , ' right' }, {}, nilable ),
252
256
language_pad = { code .language_pad , ' number' , nilable },
253
- disable_background = string_array (code .disable_background , nilable ),
257
+ disable_background = string_array (code .disable_background , {}, nilable ),
254
258
width = one_of (code .width , { ' full' , ' block' }, {}, nilable ),
255
259
left_pad = { code .left_pad , ' number' , nilable },
256
260
right_pad = { code .right_pad , ' number' , nilable },
@@ -277,7 +281,7 @@ function M.validate()
277
281
if bullet ~= nil then
278
282
append_errors (path .. ' .bullet' , bullet , {
279
283
enabled = { bullet .enabled , ' boolean' , nilable },
280
- icons = string_array (bullet .icons , nilable ),
284
+ icons = string_array (bullet .icons , {}, nilable ),
281
285
left_pad = { bullet .left_pad , ' number' , nilable },
282
286
right_pad = { bullet .right_pad , ' number' , nilable },
283
287
highlight = { bullet .highlight , ' string' , nilable },
@@ -336,7 +340,7 @@ function M.validate()
336
340
style = one_of (pipe_table .style , { ' full' , ' normal' , ' none' }, {}, nilable ),
337
341
cell = one_of (pipe_table .cell , { ' padded' , ' raw' , ' overlay' }, {}, nilable ),
338
342
min_width = { pipe_table .min_width , ' number' , nilable },
339
- border = string_array (pipe_table .border , nilable ),
343
+ border = string_array (pipe_table .border , {}, nilable ),
340
344
alignment_indicator = { pipe_table .alignment_indicator , ' string' , nilable },
341
345
head = { pipe_table .head , ' string' , nilable },
342
346
row = { pipe_table .row , ' string' , nilable },
@@ -408,7 +412,7 @@ function M.validate()
408
412
enabled = { config .enabled , ' boolean' },
409
413
max_file_size = { config .max_file_size , ' number' },
410
414
debounce = { config .debounce , ' number' },
411
- render_modes = string_array (config .render_modes , false ),
415
+ render_modes = string_array (config .render_modes , { ' boolean ' }, false ),
412
416
anti_conceal = { config .anti_conceal , ' table' },
413
417
heading = { config .heading , ' table' },
414
418
code = { config .code , ' table' },
@@ -427,7 +431,7 @@ function M.validate()
427
431
markdown_quote_query = { config .markdown_quote_query , ' string' },
428
432
inline_query = { config .inline_query , ' string' },
429
433
log_level = one_of (config .log_level , { ' debug' , ' error' }, {}, false ),
430
- file_types = string_array (config .file_types , false ),
434
+ file_types = string_array (config .file_types , {}, false ),
431
435
injections = { config .injections , ' table' },
432
436
latex = { config .latex , ' table' },
433
437
overrides = { config .overrides , ' table' },
@@ -465,7 +469,7 @@ function M.validate()
465
469
enabled = { override .enabled , ' boolean' , true },
466
470
max_file_size = { override .max_file_size , ' number' , true },
467
471
debounce = { override .debounce , ' number' , true },
468
- render_modes = string_array (override .render_modes , true ),
472
+ render_modes = string_array (override .render_modes , {}, true ),
469
473
anti_conceal = { override .anti_conceal , ' table' , true },
470
474
heading = { override .heading , ' table' , true },
471
475
code = { override .code , ' table' , true },
0 commit comments