fix(markdown): conditionally open preview browser

This commit is contained in:
Paul B. Kim 2026-03-07 22:33:45 +09:00
parent 6d2fd09ce0
commit 448f3de389
No known key found for this signature in database
1 changed files with 19 additions and 1 deletions

View File

@ -15,10 +15,28 @@ return {
vim.fn['mkdp#util#install']() vim.fn['mkdp#util#install']()
end, end,
init = function() init = function()
local browser = ''
local is_macos = vim.fn.has('macunix') == 1
if is_macos then
vim.cmd([[
function! OpenMarkdownPreview(url) abort
execute 'silent !open ' . shellescape(a:url)
endfunction
]])
elseif vim.fn.executable('google-chrome-stable') == 1 then
browser = 'google-chrome-stable'
elseif vim.fn.executable('google-chrome') == 1 then
browser = 'google-chrome'
elseif vim.fn.executable('chromium') == 1 then
browser = 'chromium'
end
vim.g.mkdp_auto_start = 0 vim.g.mkdp_auto_start = 0
vim.g.mkdp_auto_close = 1 vim.g.mkdp_auto_close = 1
vim.g.mkdp_refresh_slow = 0 vim.g.mkdp_refresh_slow = 0
vim.g.mkdp_browser = 'google-chrome-stable' vim.g.mkdp_browser = browser
vim.g.mkdp_browserfunc = is_macos and 'OpenMarkdownPreview' or ''
vim.g.mkdp_filetypes = { 'markdown' } vim.g.mkdp_filetypes = { 'markdown' }
end, end,
keys = { keys = {