1- local components = require (' render-markdown.components ' )
1+ local Config = require (' render-markdown.config ' )
22local log = require (' render-markdown.core.log' )
33local presets = require (' render-markdown.presets' )
44local treesitter = require (' render-markdown.core.treesitter' )
@@ -78,7 +78,7 @@ function M.get_config(buf)
7878 buf_config = vim .tbl_deep_extend (' force' , buf_config , override )
7979 end
8080 end
81- config = components . resolve (buf_config )
81+ config = Config . new (buf_config )
8282 configs [buf ] = config
8383 end
8484 return config
@@ -113,45 +113,49 @@ end
113113
114114--- @return string[]
115115function 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
117125
118126 --- @param value any
119- --- @param valid_values string[]
120- --- @param valid_types type[]
127+ --- @param values string[]
128+ --- @param types type[]
121129 --- @param nilable boolean
122130 --- @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 )
127133 return {
128134 value ,
129135 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 ))
131137 end ,
132- ' one of ' .. vim .inspect (valid_values ) .. ' or type ' .. vim . inspect ( valid_types ) ,
138+ ' one of ' .. vim .inspect (values ) .. suffix ,
133139 }
134140 end
135141
136142 --- @param value any
137- --- @param valid_values string[]
143+ --- @param values string[]
144+ --- @param types type[]
138145 --- @param nilable boolean
139146 --- @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 )
145149 return {
146150 value ,
147151 function (v )
148- if v == nil then
149- return nilable
152+ if vim . tbl_contains ( types , type ( v )) then
153+ return true
150154 elseif type (v ) == ' string' then
151- return vim .tbl_contains (valid_values , v )
155+ return vim .tbl_contains (values , v )
152156 elseif type (v ) == ' table' then
153157 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
155159 return false , string.format (' Index %d is %s' , i , item )
156160 end
157161 end
@@ -160,23 +164,21 @@ function M.validate()
160164 return false
161165 end
162166 end ,
163- description ,
167+ ' one or array of ' .. vim . inspect ( values ) .. suffix ,
164168 }
165169 end
166170
167- --- @param value string[]
171+ --- @param value any
172+ --- @param types type[]
168173 --- @param nilable boolean
169174 --- @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 )
175177 return {
176178 value ,
177179 function (v )
178- if v == nil then
179- return nilable
180+ if vim . tbl_contains ( types , type ( v )) then
181+ return true
180182 elseif type (v ) == ' table' then
181183 for i , item in ipairs (v ) do
182184 if type (item ) ~= ' string' then
@@ -188,10 +190,12 @@ function M.validate()
188190 return false
189191 end
190192 end ,
191- description ,
193+ ' string array ' .. suffix ,
192194 }
193195 end
194196
197+ local errors = {}
198+
195199 --- @param suffix string
196200 --- @param input table<string , any>
197201 --- @param opts table<string , vim.validate.Spec>
@@ -227,18 +231,18 @@ function M.validate()
227231 enabled = { heading .enabled , ' boolean' , nilable },
228232 sign = { heading .sign , ' boolean' , nilable },
229233 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 ),
233237 left_pad = { heading .left_pad , ' number' , nilable },
234238 right_pad = { heading .right_pad , ' number' , nilable },
235239 min_width = { heading .min_width , ' number' , nilable },
236240 border = { heading .border , ' boolean' , nilable },
237241 border_prefix = { heading .border_prefix , ' boolean' , nilable },
238242 above = { heading .above , ' string' , nilable },
239243 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 ),
242246 })
243247 end
244248
@@ -250,7 +254,7 @@ function M.validate()
250254 style = one_of (code .style , { ' full' , ' normal' , ' language' , ' none' }, {}, nilable ),
251255 position = one_of (code .position , { ' left' , ' right' }, {}, nilable ),
252256 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 ),
254258 width = one_of (code .width , { ' full' , ' block' }, {}, nilable ),
255259 left_pad = { code .left_pad , ' number' , nilable },
256260 right_pad = { code .right_pad , ' number' , nilable },
@@ -277,7 +281,7 @@ function M.validate()
277281 if bullet ~= nil then
278282 append_errors (path .. ' .bullet' , bullet , {
279283 enabled = { bullet .enabled , ' boolean' , nilable },
280- icons = string_array (bullet .icons , nilable ),
284+ icons = string_array (bullet .icons , {}, nilable ),
281285 left_pad = { bullet .left_pad , ' number' , nilable },
282286 right_pad = { bullet .right_pad , ' number' , nilable },
283287 highlight = { bullet .highlight , ' string' , nilable },
@@ -336,7 +340,7 @@ function M.validate()
336340 style = one_of (pipe_table .style , { ' full' , ' normal' , ' none' }, {}, nilable ),
337341 cell = one_of (pipe_table .cell , { ' padded' , ' raw' , ' overlay' }, {}, nilable ),
338342 min_width = { pipe_table .min_width , ' number' , nilable },
339- border = string_array (pipe_table .border , nilable ),
343+ border = string_array (pipe_table .border , {}, nilable ),
340344 alignment_indicator = { pipe_table .alignment_indicator , ' string' , nilable },
341345 head = { pipe_table .head , ' string' , nilable },
342346 row = { pipe_table .row , ' string' , nilable },
@@ -408,7 +412,7 @@ function M.validate()
408412 enabled = { config .enabled , ' boolean' },
409413 max_file_size = { config .max_file_size , ' number' },
410414 debounce = { config .debounce , ' number' },
411- render_modes = string_array (config .render_modes , false ),
415+ render_modes = string_array (config .render_modes , { ' boolean ' }, false ),
412416 anti_conceal = { config .anti_conceal , ' table' },
413417 heading = { config .heading , ' table' },
414418 code = { config .code , ' table' },
@@ -427,7 +431,7 @@ function M.validate()
427431 markdown_quote_query = { config .markdown_quote_query , ' string' },
428432 inline_query = { config .inline_query , ' string' },
429433 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 ),
431435 injections = { config .injections , ' table' },
432436 latex = { config .latex , ' table' },
433437 overrides = { config .overrides , ' table' },
@@ -465,7 +469,7 @@ function M.validate()
465469 enabled = { override .enabled , ' boolean' , true },
466470 max_file_size = { override .max_file_size , ' number' , true },
467471 debounce = { override .debounce , ' number' , true },
468- render_modes = string_array (override .render_modes , true ),
472+ render_modes = string_array (override .render_modes , {}, true ),
469473 anti_conceal = { override .anti_conceal , ' table' , true },
470474 heading = { override .heading , ' table' , true },
471475 code = { override .code , ' table' , true },
0 commit comments