refactor(config): replace array preset syntax with preset_name = true (#3)
* refactor(config): replace array preset syntax with preset_name = true Problem: setup() mixed array entries (preset names) and hash entries (custom providers keyed by filetype), requiring verbose vim.tbl_deep_extend boilerplate to override presets. Solution: unify under a single key=value model. Keys are preset names or filetypes; true registers the preset as-is, a table deep-merges with the matching preset (or registers a custom provider if no preset matches), and false is a no-op. Array entries are dropped. Also adds -f gfm to presets.github args so pandoc parses input as GFM. * ci: format * fix(presets): parenthesize gsub output to suppress redundant-return-value
This commit is contained in:
parent
673573044f
commit
2d212aa220
6 changed files with 73 additions and 56 deletions
|
|
@ -68,15 +68,17 @@ function M.setup(opts)
|
|||
if k == 'debug' then
|
||||
vim.validate('preview.setup opts.debug', v, { 'boolean', 'string' })
|
||||
debug = v
|
||||
elseif type(k) == 'number' then
|
||||
vim.validate('preview.setup preset name', v, 'string')
|
||||
local preset = presets[v]
|
||||
elseif type(k) ~= 'number' then
|
||||
local preset = presets[k]
|
||||
if preset then
|
||||
providers[preset.ft] = preset
|
||||
if v == true then
|
||||
providers[preset.ft] = preset
|
||||
elseif type(v) == 'table' then
|
||||
providers[preset.ft] = vim.tbl_deep_extend('force', preset, v)
|
||||
end
|
||||
elseif type(v) == 'table' then
|
||||
providers[k] = v
|
||||
end
|
||||
else
|
||||
vim.validate('preview.setup provider config', v, 'table')
|
||||
providers[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ M.typst = {
|
|||
return { ctx.file }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return ctx.file:gsub('%.typ$', '.pdf')
|
||||
return (ctx.file:gsub('%.typ$', '.pdf'))
|
||||
end,
|
||||
open = { 'xdg-open' },
|
||||
}
|
||||
|
|
@ -21,7 +21,7 @@ M.latex = {
|
|||
return { '-pdf', '-interaction=nonstopmode', ctx.file }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return ctx.file:gsub('%.tex$', '.pdf')
|
||||
return (ctx.file:gsub('%.tex$', '.pdf'))
|
||||
end,
|
||||
clean = function(ctx)
|
||||
return { 'latexmk', '-c', ctx.file }
|
||||
|
|
@ -38,7 +38,7 @@ M.markdown = {
|
|||
return { ctx.file, '-s', '--embed-resources', '-o', output }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return ctx.file:gsub('%.md$', '.html')
|
||||
return (ctx.file:gsub('%.md$', '.html'))
|
||||
end,
|
||||
clean = function(ctx)
|
||||
return { 'rm', '-f', (ctx.file:gsub('%.md$', '.html')) }
|
||||
|
|
@ -53,17 +53,19 @@ M.github = {
|
|||
args = function(ctx)
|
||||
local output = ctx.file:gsub('%.md$', '.html')
|
||||
return {
|
||||
'-f',
|
||||
'gfm',
|
||||
ctx.file,
|
||||
'-s',
|
||||
'--embed-resources',
|
||||
'--css',
|
||||
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/github.css',
|
||||
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
|
||||
'-o',
|
||||
output,
|
||||
}
|
||||
end,
|
||||
output = function(ctx)
|
||||
return ctx.file:gsub('%.md$', '.html')
|
||||
return (ctx.file:gsub('%.md$', '.html'))
|
||||
end,
|
||||
clean = function(ctx)
|
||||
return { 'rm', '-f', (ctx.file:gsub('%.md$', '.html')) }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue