]> Arthur Taft Gitweb - nvim.git/blob - lua/plugins/render_markdown.lua
Initial commit
[nvim.git] / lua / plugins / render_markdown.lua
1 return {
2         {
3                 "MeanderingProgrammer/render-markdown.nvim",
4                 ft = { "markdown" },
5                 dependencies = {
6                         "nvim-treesitter/nvim-treesitter",
7                         "nvim-tree/nvim-web-devicons",
8                 },
9                 keys = {
10                         -- Open a right split showing the SAME buffer, render only in that right window
11                         {
12                                 "<leader>mr",
13                                 function()
14                                         local cur = vim.api.nvim_get_current_buf()
15                                         vim.cmd("vsplit")
16                                         vim.cmd("wincmd l")
17                                         vim.api.nvim_win_set_buf(0, cur)
18
19                                         -- Optional: fix the width of the preview pane (comment out if not desired)
20                                         -- vim.cmd("vertical resize 88")
21
22                                         require("render-markdown").enable() -- enable only in the right window
23                                 end,
24                                 desc = "Markdown: open rendered view (right split)",
25                         },
26
27                         -- Disable rendering in the current window and close the split
28                         {
29                                 "<leader>mR",
30                                 function()
31                                         require("render-markdown").disable()
32                                         -- Close the right split if you're currently in it
33                                         if #vim.api.nvim_list_wins() > 1 then
34                                                 vim.cmd("wincmd l | close")
35                                         end
36                                 end,
37                                 desc = "Markdown: close rendered view",
38                         },
39
40                         -- Toggle inline rendering in the current window (no split)
41                         {
42                                 "<leader>mi",
43                                 function()
44                                         vim.cmd("RenderMarkdown toggle") -- built-in toggle command
45                                 end,
46                                 desc = "Markdown: toggle inline render",
47                         },
48                 },
49                 opts = {
50                         -- Good starting defaults; tweak as you like
51                         heading = {
52                                 enabled = true,
53                                 sign = true,
54                                 icons = { "▎", "▎", "▎", "▎", "▎", "▎" },
55                         },
56                         bullet = { enabled = true },
57                         checkbox = { enabled = true },
58                         code = { enabled = true, sign = true }, -- prettify fenced code blocks
59                         link = { enabled = true },
60                         table = { enabled = true },
61                 },
62                 config = function(_, opts)
63                         require("render-markdown").setup(opts)
64
65                         -- Nice conceal defaults for markdown buffers
66                         vim.api.nvim_create_autocmd("FileType", {
67                                 pattern = { "markdown" },
68                                 callback = function(ev)
69                                         local win = vim.fn.bufwinid(ev.buf)
70                                         if win ~= -1 then
71                                                 vim.api.nvim_win_set_option(win, "conceallevel", 2)
72                                                 vim.api.nvim_win_set_option(win, "concealcursor", "nc")
73                                         end
74                                 end,
75                         })
76                 end,
77         },
78 }