@@ -4,7 +4,7 @@ local M = {}
4
4
5
5
function M .check ()
6
6
vim .health .start (' markdown.nvim [configuration]' )
7
- local errors = M . check_config ( state .config )
7
+ local errors = state .validate ( )
8
8
if # errors == 0 then
9
9
vim .health .ok (' valid' )
10
10
end
@@ -44,191 +44,6 @@ function M.check()
44
44
end
45
45
end
46
46
47
- --- @param config render.md.Config
48
- --- @return string[]
49
- function M .check_config (config )
50
- local errors = {}
51
-
52
- --- @param value string
53
- --- @param valid_values string[]
54
- --- @return vim.validate.Spec
55
- local function one_of (value , valid_values )
56
- return {
57
- value ,
58
- function (v )
59
- return vim .tbl_contains (valid_values , v )
60
- end ,
61
- ' one of ' .. vim .inspect (valid_values ),
62
- }
63
- end
64
-
65
- --- @param path string ?
66
- --- @param opts table<string , vim.validate.Spec>
67
- local function append_errors (path , opts )
68
- local ok , err = pcall (vim .validate , opts )
69
- if not ok then
70
- if path == nil then
71
- table.insert (errors , err )
72
- else
73
- table.insert (errors , path .. ' .' .. err )
74
- end
75
- end
76
- end
77
-
78
- --- @param path string
79
- --- @param values string[]
80
- local function all_strings (path , values )
81
- for i , value in ipairs (values ) do
82
- append_errors (path , {
83
- [tostring (i )] = { value , ' string' },
84
- })
85
- end
86
- end
87
-
88
- append_errors (nil , {
89
- enabled = { config .enabled , ' boolean' },
90
- max_file_size = { config .max_file_size , ' number' },
91
- markdown_query = { config .markdown_query , ' string' },
92
- markdown_quote_query = { config .markdown_quote_query , ' string' },
93
- inline_query = { config .inline_query , ' string' },
94
- log_level = one_of (config .log_level , { ' debug' , ' error' }),
95
- file_types = { config .file_types , ' table' },
96
- render_modes = { config .render_modes , ' table' },
97
- latex = { config .latex , ' table' },
98
- heading = { config .heading , ' table' },
99
- code = { config .code , ' table' },
100
- dash = { config .dash , ' table' },
101
- bullet = { config .bullet , ' table' },
102
- pipe_table = { config .pipe_table , ' table' },
103
- checkbox = { config .checkbox , ' table' },
104
- quote = { config .quote , ' table' },
105
- callout = { config .callout , ' table' },
106
- link = { config .link , ' table' },
107
- win_options = { config .win_options , ' table' },
108
- custom_handlers = { config .custom_handlers , ' table' },
109
- })
110
-
111
- all_strings (' file_types' , config .file_types )
112
- all_strings (' render_modes' , config .render_modes )
113
-
114
- local latex = config .latex
115
- append_errors (' latex' , {
116
- enabled = { latex .enabled , ' boolean' },
117
- converter = { latex .converter , ' string' },
118
- highlight = { latex .highlight , ' string' },
119
- })
120
-
121
- local heading = config .heading
122
- append_errors (' heading' , {
123
- enabled = { heading .enabled , ' boolean' },
124
- icons = { heading .icons , ' table' },
125
- signs = { heading .signs , ' table' },
126
- backgrounds = { heading .backgrounds , ' table' },
127
- foregrounds = { heading .foregrounds , ' table' },
128
- })
129
- all_strings (' heading.icons' , heading .icons )
130
- all_strings (' heading.signs' , heading .signs )
131
- all_strings (' heading.backgrounds' , heading .backgrounds )
132
- all_strings (' heading.foregrounds' , heading .foregrounds )
133
-
134
- local code = config .code
135
- append_errors (' code' , {
136
- enabled = { code .enabled , ' boolean' },
137
- style = one_of (code .style , { ' full' , ' language' , ' normal' , ' none' }),
138
- highlight = { code .highlight , ' string' },
139
- })
140
-
141
- local dash = config .dash
142
- append_errors (' dash' , {
143
- enabled = { dash .enabled , ' boolean' },
144
- icon = { dash .icon , ' string' },
145
- highlight = { dash .highlight , ' string' },
146
- })
147
-
148
- local bullet = config .bullet
149
- append_errors (' bullet' , {
150
- enabled = { bullet .enabled , ' boolean' },
151
- icons = { bullet .icons , ' table' },
152
- highlight = { bullet .highlight , ' string' },
153
- })
154
- all_strings (' bullet.icons' , bullet .icons )
155
-
156
- local checkbox = config .checkbox
157
- append_errors (' checkbox' , {
158
- enabled = { checkbox .enabled , ' boolean' },
159
- unchecked = { checkbox .unchecked , ' table' },
160
- checked = { checkbox .checked , ' table' },
161
- custom = { checkbox .custom , ' table' },
162
- })
163
- local unchecked = checkbox .unchecked
164
- append_errors (' checkbox.unchecked' , {
165
- icon = { unchecked .icon , ' string' },
166
- highlight = { unchecked .highlight , ' string' },
167
- })
168
- local checked = checkbox .checked
169
- append_errors (' checkbox.checked' , {
170
- icon = { checked .icon , ' string' },
171
- highlight = { checked .highlight , ' string' },
172
- })
173
- for name , component in pairs (checkbox .custom ) do
174
- append_errors (' checkbox.custom.' .. name , {
175
- raw = { component .raw , ' string' },
176
- rendered = { component .rendered , ' string' },
177
- highlight = { component .highlight , ' string' },
178
- })
179
- end
180
-
181
- local quote = config .quote
182
- append_errors (' quote' , {
183
- enabled = { quote .enabled , ' boolean' },
184
- icon = { quote .icon , ' string' },
185
- highlight = { quote .highlight , ' string' },
186
- })
187
-
188
- local pipe_table = config .pipe_table
189
- append_errors (' pipe_table' , {
190
- enabled = { pipe_table .enabled , ' boolean' },
191
- style = one_of (pipe_table .style , { ' full' , ' normal' , ' none' }),
192
- cell = one_of (pipe_table .cell , { ' overlay' , ' raw' }),
193
- border = { pipe_table .border , ' table' },
194
- head = { pipe_table .head , ' string' },
195
- row = { pipe_table .row , ' string' },
196
- })
197
- all_strings (' pipe_table.border' , pipe_table .border )
198
-
199
- for name , component in pairs (config .callout ) do
200
- append_errors (' callout.' .. name , {
201
- raw = { component .raw , ' string' },
202
- rendered = { component .rendered , ' string' },
203
- highlight = { component .highlight , ' string' },
204
- })
205
- end
206
-
207
- local link = config .link
208
- append_errors (' link' , {
209
- enabled = { link .enabled , ' boolean' },
210
- image = { link .image , ' string' },
211
- hyperlink = { link .hyperlink , ' string' },
212
- highlight = { link .highlight , ' string' },
213
- })
214
-
215
- for name , win_option in pairs (config .win_options ) do
216
- append_errors (' win_options.' .. name , {
217
- default = { win_option .default , { ' number' , ' string' } },
218
- rendered = { win_option .rendered , { ' number' , ' string' } },
219
- })
220
- end
221
-
222
- for name , handler in pairs (config .custom_handlers ) do
223
- append_errors (' custom_handlers.' .. name , {
224
- render = { handler .render , ' function' },
225
- extends = { handler .extends , ' boolean' , true },
226
- })
227
- end
228
-
229
- return errors
230
- end
231
-
232
47
--- @param name string
233
48
--- @param advice string ?
234
49
function M .check_parser (name , advice )
0 commit comments