summaryrefslogtreecommitdiff
path: root/config/nvim/lua/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'config/nvim/lua/plugins')
-rw-r--r--config/nvim/lua/plugins/lsp.lua1
-rw-r--r--config/nvim/lua/plugins/markdown.lua73
2 files changed, 74 insertions, 0 deletions
diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua
index c3853b3..1470177 100644
--- a/config/nvim/lua/plugins/lsp.lua
+++ b/config/nvim/lua/plugins/lsp.lua
@@ -128,6 +128,7 @@ return {
local TS = require("nvim-treesitter")
local ensure_installed = {
"astro", "go", "html", "javascript", "lua", "python", "tsx", "typescript",
+ "markdown", "markdown_inline",
}
local installed = TS.get_installed("parsers")
local to_install = vim.tbl_filter(function(lang)
diff --git a/config/nvim/lua/plugins/markdown.lua b/config/nvim/lua/plugins/markdown.lua
new file mode 100644
index 0000000..b298554
--- /dev/null
+++ b/config/nvim/lua/plugins/markdown.lua
@@ -0,0 +1,73 @@
+-- In-buffer markdown rendering: headings, code blocks, tables, callouts and
+-- checkboxes rendered in place, in the one buffer. No preview window or split.
+-- The cursor line keeps its raw syntax (the plugin's anti_conceal), so editing
+-- is unaffected. <leader>mt toggles rendering for the current buffer.
+return {
+ {
+ "MeanderingProgrammer/render-markdown.nvim",
+ ft = { "markdown" },
+ dependencies = { "nvim-tree/nvim-web-devicons" },
+ opts = {},
+ config = function(_, opts)
+ require("render-markdown").setup(opts)
+
+ -- render-markdown takes its per-level heading colours from the
+ -- treesitter captures @markup.heading.{1..6}.markdown. None of the
+ -- colourschemes under config/nvim/colors/ define treesitter groups
+ -- at all -- happy_hacking, onehalfdark and ayu were each checked --
+ -- so those captures resolve to nothing and every heading level
+ -- renders with no colour. Supply a ramp, but only where the theme
+ -- left the group undefined, so a theme that does define them keeps
+ -- its own. Re-applied on ColorScheme, since cfg-watch switches the
+ -- theme at runtime and `:colorscheme` can clear highlight groups.
+ local ramps = {
+ dark = {
+ { "#F3F2CC", 230 },
+ { "#FAD566", 221 },
+ { "#B3EBBF", 157 },
+ { "#81A2C7", 103 },
+ { "#F77EBD", 211 },
+ { "#fcb280", 179 },
+ },
+ light = {
+ { "#2F2F2F", 236 },
+ { "#8C6D1F", 136 },
+ { "#3F6B3F", 22 },
+ { "#3A5A8C", 24 },
+ { "#8C3A6B", 89 },
+ { "#8C5A2F", 130 },
+ },
+ }
+ local function set_heading_colors()
+ local ramp = ramps[vim.o.background] or ramps.dark
+ for level = 1, 6 do
+ local name = "RenderMarkdownH" .. level
+ -- Put render-markdown's own link back first, so a theme that
+ -- does define the capture wins, and so this stays correct
+ -- after a theme switch.
+ vim.api.nvim_set_hl(0, name, { link = "@markup.heading." .. level .. ".markdown" })
+ local hl = vim.api.nvim_get_hl(0, { name = name })
+ if not (hl.fg or hl.bg or hl.bold or hl.italic or hl.underline) then
+ vim.api.nvim_set_hl(0, name, {
+ fg = ramp[level][1],
+ ctermfg = ramp[level][2],
+ bold = true,
+ })
+ end
+ end
+ end
+ set_heading_colors()
+ vim.api.nvim_create_autocmd("ColorScheme", { callback = set_heading_colors })
+
+ vim.api.nvim_create_autocmd("FileType", {
+ pattern = "markdown",
+ callback = function(event)
+ vim.keymap.set("n", "<leader>mt", "<cmd>RenderMarkdown buf_toggle<cr>", {
+ buffer = event.buf,
+ desc = "Toggle markdown rendering",
+ })
+ end,
+ })
+ end,
+ },
+}