Skip to content

Commit 448f3de

Browse files
committed
fix(markdown): conditionally open preview browser
1 parent 6d2fd09 commit 448f3de

1 file changed

Lines changed: 19 additions & 1 deletion

File tree

lua/custom/plugins/markdown.lua

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,28 @@ return {
1515
vim.fn['mkdp#util#install']()
1616
end,
1717
init = function()
18+
local browser = ''
19+
local is_macos = vim.fn.has('macunix') == 1
20+
21+
if is_macos then
22+
vim.cmd([[
23+
function! OpenMarkdownPreview(url) abort
24+
execute 'silent !open ' . shellescape(a:url)
25+
endfunction
26+
]])
27+
elseif vim.fn.executable('google-chrome-stable') == 1 then
28+
browser = 'google-chrome-stable'
29+
elseif vim.fn.executable('google-chrome') == 1 then
30+
browser = 'google-chrome'
31+
elseif vim.fn.executable('chromium') == 1 then
32+
browser = 'chromium'
33+
end
34+
1835
vim.g.mkdp_auto_start = 0
1936
vim.g.mkdp_auto_close = 1
2037
vim.g.mkdp_refresh_slow = 0
21-
vim.g.mkdp_browser = 'google-chrome-stable'
38+
vim.g.mkdp_browser = browser
39+
vim.g.mkdp_browserfunc = is_macos and 'OpenMarkdownPreview' or ''
2240
vim.g.mkdp_filetypes = { 'markdown' }
2341
end,
2442
keys = {

0 commit comments

Comments
 (0)