nvim: Use peek for markdown preview where possible

On machines that have deno installed, we use peek instead of
markdown-preview for html-based previews of md files. The preview is
more responsive and in a neater package, as well as just not relying on
any vim plugin stuff to the same degree.
We still fall back to the old markdown-preview if no deno executable is
available.

We also change the key maps slightly to prepare for future 'prose' or
'preview' based mappings: All mappings are registered under the
`<leader>p` layer, with md preview being `<leader>pp` and various
mindmap operations moved to `<leader>pm`.
This commit is contained in:
Marty Oehme 2024-06-06 20:50:37 +02:00
parent b69548fa38
commit 1771a61334
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 33 additions and 5 deletions

View file

@ -5,7 +5,7 @@ if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>e"] = { name = "+criticmarkup" } }) require("which-key").register({ ["<localleader>e"] = { name = "+criticmarkup" } })
end end
if require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then if require("core.util").is_available("zk") and require("zk.util").notebook_root(vim.fn.expand("%:p")) ~= nil then
map("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<cr>", { silent = true }) map("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<cr>", { silent = true })
end end
@ -22,11 +22,26 @@ map("n", "[c", "?^```<cr>n}:nohl<cr>", { desc = "previous code cell" })
map("n", "<localleader>co", "o```python<cr><cr>```<esc>k", { desc = "Insert quarto cell below" }) map("n", "<localleader>co", "o```python<cr><cr>```<esc>k", { desc = "Insert quarto cell below" })
map("n", "<localleader>cO", "O```python<cr><cr>```<esc>k", { desc = "Insert quarto cell above" }) map("n", "<localleader>cO", "O```python<cr><cr>```<esc>k", { desc = "Insert quarto cell above" })
if require("core.util").is_available("which-key") then
require("which-key").register({ ["<localleader>p"] = { name = "+prose" } })
end
-- show nice md preview in browser (auto-syncs scrolling) -- show nice md preview in browser (auto-syncs scrolling)
map("n", "<localleader>cp", "<Plug>MarkdownPreviewToggle", { desc = "show md preview" }) if require("core.util").is_available("peek") then
local peek = require("peek")
local function togglePeek()
if peek.is_open() then
peek.close()
else
peek.open()
end
end
map("n", "<leader>pp", togglePeek, { desc = "show md preview" })
else
map("n", "<leader>pp", "<Plug>MarkdownPreviewToggle", { desc = "show md preview" })
end
-- create mindmaps directly from markdown! requires external executable -- create mindmaps directly from markdown! requires external executable
if vim.fn.executable("markmap") then if vim.fn.executable("markmap") then
map("n", "<localleader>cm", "<cmd>MarkmapOpen<cr>", { desc = "open md mindmap" }) map("n", "<leader>pm", "<cmd>MarkmapOpen<cr>", { desc = "open md mindmap" })
map("n", "<localleader>cM", "<cmd>MarkmapWatch<cr>", { desc = "watch for md mindmap" }) map("n", "<leader>pM", "<cmd>MarkmapWatch<cr>", { desc = "watch for md mindmap" })
end end

View file

@ -8,7 +8,7 @@ local prose_plugs = {
config = true, config = true,
cmd = { "ZenMode" }, cmd = { "ZenMode" },
dependencies = { "folke/twilight.nvim" }, dependencies = { "folke/twilight.nvim" },
keys = { { "<leader>sz", ":ZenMode<cr>", { silent = true } } }, keys = { { "<leader>sz", ":ZenMode<cr>", silent = true, desc = "toggle zen mode" } },
}, },
{ {
"andrewferrier/wrapping.nvim", "andrewferrier/wrapping.nvim",
@ -48,8 +48,21 @@ local prose_plugs = {
ft = writing_ft, ft = writing_ft,
}, },
-- generate an auto-updating html preview for md files -- generate an auto-updating html preview for md files
-- uses the very nice peek if deno is available, otherwise falls back to markdown-preview
{
"toppair/peek.nvim",
event = { "VeryLazy" },
cond = vim.fn.executable("deno") == 1,
build = "deno task --quiet build:fast",
config = function()
require("peek").setup()
vim.api.nvim_create_user_command("PeekOpen", require("peek").open, {})
vim.api.nvim_create_user_command("PeekClose", require("peek").close, {})
end,
},
{ {
"iamcco/markdown-preview.nvim", "iamcco/markdown-preview.nvim",
cond = vim.fn.executable("deno") == 0,
build = function() build = function()
vim.fn["mkdp#util#install"]() vim.fn["mkdp#util#install"]()
end, end,