preview.nvim/lua/preview/presets.lua
Barrett Ruth edfe3b6117
refactor(presets): replace xdg-open with vim.ui.open
Problem: all presets hardcoded `open = { 'xdg-open' }`, making them
Linux-only. The compiler already handles `open = true` via
`vim.ui.open()`, which is cross-platform.

Solution: change all four presets to `open = true`.
2026-03-03 13:33:13 -05:00

76 lines
1.6 KiB
Lua

local M = {}
---@type preview.ProviderConfig
M.typst = {
ft = 'typst',
cmd = { 'typst', 'compile' },
args = function(ctx)
return { ctx.file }
end,
output = function(ctx)
return (ctx.file:gsub('%.typ$', '.pdf'))
end,
open = true,
}
---@type preview.ProviderConfig
M.latex = {
ft = 'tex',
cmd = { 'latexmk' },
args = function(ctx)
return { '-pdf', '-interaction=nonstopmode', ctx.file }
end,
output = function(ctx)
return (ctx.file:gsub('%.tex$', '.pdf'))
end,
clean = function(ctx)
return { 'latexmk', '-c', ctx.file }
end,
open = true,
}
---@type preview.ProviderConfig
M.markdown = {
ft = 'markdown',
cmd = { 'pandoc' },
args = function(ctx)
local output = ctx.file:gsub('%.md$', '.html')
return { ctx.file, '-s', '--embed-resources', '-o', output }
end,
output = function(ctx)
return (ctx.file:gsub('%.md$', '.html'))
end,
clean = function(ctx)
return { 'rm', '-f', (ctx.file:gsub('%.md$', '.html')) }
end,
open = true,
}
---@type preview.ProviderConfig
M.github = {
ft = 'markdown',
cmd = { 'pandoc' },
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/dist/gfm.css',
'-o',
output,
}
end,
output = function(ctx)
return (ctx.file:gsub('%.md$', '.html'))
end,
clean = function(ctx)
return { 'rm', '-f', (ctx.file:gsub('%.md$', '.html')) }
end,
open = true,
}
return M