Skip to content

Commit

Permalink
Update markdown-preview config function 💚
Browse files Browse the repository at this point in the history
Installation/updates are now asynchronous thanks to plenary
Includes a temporary fix for iamcco/markdown-preview.nvim#612
  • Loading branch information
scottmckendry committed Oct 17, 2023
1 parent d5dc0fb commit 0ff476a
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions nvim/lua/plugins/markdown-preview.lua
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
return {
"iamcco/markdown-preview.nvim",
dependencies = {
"nvim-lua/plenary.nvim",
},
cmd = { "MarkdownPreview", "MarkdownPreviewStop", "MarkdownPreviewToggle" },
init = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
ft = { "markdown" },
config = function()
-- Can't get lazy build to work ¯\_(ツ)_/¯
-- This first time loading the plugin, there will be a significant delay becuase the function is synchronous, but after that it shouldn't be noticeable
-- TODO: Either figure out how to get lazy build to work, or figure out how to make this asynchronous
local job = require("plenary.job")
local install_path = vim.fn.stdpath("data") .. "/lazy/markdown-preview.nvim/app"
local node_modules = install_path .. "/node_modules"
if vim.fn.empty(vim.fn.glob(node_modules)) > 0 then
vim.cmd("!cd " .. install_path .. " && npm install")
local cmd = "bash"

if vim.fn.has("win64") == 1 then
cmd = "pwsh"
end

job:new({
command = cmd,
args = { "-c", "npm install && git restore ." },
cwd = install_path,
on_exit = function()
print("Finished installing markdown-preview.nvim")
end,
on_stderr = function(_, data)
print(data)
end,
}):start()

-- Options
vim.g.mkdp_auto_close = 0
end,
Expand Down

0 comments on commit 0ff476a

Please sign in to comment.