feat: enable and remap glow preview

This commit is contained in:
NotAShelf 2023-03-01 14:00:26 +03:00
parent cccc7f5bda
commit d817b27405
No known key found for this signature in database
GPG key ID: 5B5C8895F28445F1
3 changed files with 46 additions and 9 deletions

View file

@ -8,13 +8,26 @@ with lib; let
cfg = config.vim.markdown.glow; cfg = config.vim.markdown.glow;
in { in {
config = (mkIf cfg.enable) { config = (mkIf cfg.enable) {
vim.startPlugins = ["glow-nvim"]; vim.startPlugins = [
"glow-nvim"
];
vim.globals = { vim.globals = {
"glow_binary_path" = "${pkgs.glow}/bin"; "glow_binary_path" = "${pkgs.glow}/bin";
}; };
vim.configRC.glow = nvim.dag.entryAnywhere '' vim.configRC.glow-nvim = nvim.dag.entryAnywhere ''
autocmd FileType markdown noremap <leader>p :Glow<CR> autocmd FileType markdown noremap <leader>pm :Glow<CR>
'';
vim.luaConfigRC.glow-nvim = nvim.dag.entryAnywhere ''
require('glow').setup({
-- use glow path from vim.globals
path = vim.g.glow_binary_path,
border = "${toString cfg.border}",
pager = ${boolToString cfg.pager},
width = 120,
})
''; '';
}; };
} }

View file

@ -6,13 +6,31 @@
}: }:
with lib; with lib;
with builtins; let with builtins; let
cfg = config.vim.markdown; cfg = config.vim.markdown.glow;
in { in {
options.vim.markdown = { options.vim.markdown.glow = {
glow.enable = mkOption { enable = mkOption {
type = types.bool; type = types.bool;
default = false; default = false;
description = "Enable markdown preview in neovim with glow"; description = "Enable markdown preview in neovim with glow";
}; };
border = mkOption {
type = types.enum ["shadow" "rounded" "single" "double" "none"];
default = "double";
description = "Border style for glow preview";
};
# style should be either light or dark
style = mkOption {
type = types.enum ["light" "dark"];
default = "dark";
description = "Style for glow preview";
};
pager = mkOption {
type = types.bool;
default = false;
description = "Enable pager for glow preview";
};
}; };
} }

View file

@ -107,9 +107,15 @@ in {
'' ''
else "" else ""
} }
${
}) if config.vim.markdown.glow.enable
then ''
-- Markdown
["<leader>pm"] = { name = "+Preview Markdown" },
''
else ""
}
})
''; '';
}; };
} }