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
|
|
@ -22,7 +22,7 @@ describe('preview', function()
|
|||
assert.are.same({}, config.providers)
|
||||
end)
|
||||
|
||||
it('accepts full provider config via hash entry', function()
|
||||
it('merges override table with matching preset', function()
|
||||
helpers.reset_config({
|
||||
typst = {
|
||||
cmd = { 'typst', 'compile' },
|
||||
|
|
@ -33,8 +33,8 @@ describe('preview', function()
|
|||
assert.is_not_nil(config.providers.typst)
|
||||
end)
|
||||
|
||||
it('resolves array preset names to provider configs', function()
|
||||
helpers.reset_config({ 'typst', 'markdown' })
|
||||
it('resolves preset = true to provider config', function()
|
||||
helpers.reset_config({ typst = true, markdown = true })
|
||||
local config = require('preview').get_config()
|
||||
local presets = require('preview.presets')
|
||||
assert.are.same(presets.typst, config.providers.typst)
|
||||
|
|
@ -42,14 +42,14 @@ describe('preview', function()
|
|||
end)
|
||||
|
||||
it('resolves latex preset under tex filetype', function()
|
||||
helpers.reset_config({ 'latex' })
|
||||
helpers.reset_config({ latex = true })
|
||||
local config = require('preview').get_config()
|
||||
local presets = require('preview.presets')
|
||||
assert.are.same(presets.latex, config.providers.tex)
|
||||
end)
|
||||
|
||||
it('resolves github preset under markdown filetype', function()
|
||||
helpers.reset_config({ 'github' })
|
||||
helpers.reset_config({ github = true })
|
||||
local config = require('preview').get_config()
|
||||
local presets = require('preview.presets')
|
||||
assert.are.same(presets.github, config.providers.markdown)
|
||||
|
|
@ -59,7 +59,7 @@ describe('preview', function()
|
|||
describe('resolve_provider', function()
|
||||
before_each(function()
|
||||
helpers.reset_config({
|
||||
typst = { cmd = { 'typst', 'compile' } },
|
||||
typst = true,
|
||||
})
|
||||
preview = require('preview')
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -139,16 +139,31 @@ describe('presets', function()
|
|||
local args = presets.github.args(md_ctx)
|
||||
assert.is_table(args)
|
||||
assert.are.same({
|
||||
'-f',
|
||||
'gfm',
|
||||
'/tmp/document.md',
|
||||
'-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',
|
||||
'/tmp/document.html',
|
||||
}, args)
|
||||
end)
|
||||
|
||||
it('args include -f and gfm flags', function()
|
||||
local args = presets.github.args(md_ctx)
|
||||
local idx = nil
|
||||
for i, v in ipairs(args) do
|
||||
if v == '-f' then
|
||||
idx = i
|
||||
break
|
||||
end
|
||||
end
|
||||
assert.is_not_nil(idx)
|
||||
assert.are.equal('gfm', args[idx + 1])
|
||||
end)
|
||||
|
||||
it('returns html output path', function()
|
||||
local output = presets.github.output(md_ctx)
|
||||
assert.is_string(output)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue