feat(nvim): add remote markdown previewing
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2024-12-16 23:44:33 -05:00
parent 6c5ef370c5
commit 3ac4c45c4d

View file

@ -1,6 +1,7 @@
self: { self: {
config, config,
lib, lib,
osConfig,
pkgs, pkgs,
self, self,
... ...
@ -8,10 +9,18 @@ self: {
inherit (self.inputs) vimplugin-easytables-src; inherit (self.inputs) vimplugin-easytables-src;
inherit (self.lib.${pkgs.system}) buildPlugin; inherit (self.lib.${pkgs.system}) buildPlugin;
inherit (lib) attrValues mkIf; inherit (lib) attrValues concatStringsSep mkIf;
cfg = config.programs.neovim; cfg = config.programs.neovim;
isServer = osConfig.roles.server.sshd.enable or false;
githubCSS = pkgs.fetchurl {
url = "https://raw.githubusercontent.com/OzakIOne/markdown-github-dark/5bd0bcf3ad20cf9f58591f97a597fd68fc699f8e/style.css";
hash = "sha256-deQvQOOyK6iP7kjVrgEdFTyOP80RWXMrETs6gi7DTmo=";
};
in { in {
# live-server --quiet --browser=firefox --open=%outputfile% --watch=%outputfile% --wait=800
config = mkIf cfg.enableIde { config = mkIf cfg.enableIde {
programs = { programs = {
neovim = { neovim = {
@ -60,7 +69,27 @@ in {
{ {
plugin = pkgs.vimPlugins.knap; plugin = pkgs.vimPlugins.knap;
type = "lua"; type = "lua";
config = config = let
mdToPDF = "pandoc --css ${githubCSS} %docroot% -o /tmp/%outputfile%";
mdToPDFViewer = "sioyek /tmp/%outputfile%";
mdToHTML = "pandoc --standalone --embed-resource --highlight-style=breezedark --css ${githubCSS} %docroot% -o /tmp/%outputfile%";
mdToHTMLViewer =
if isServer
then
concatStringsSep " " [
"${pkgs.nodePackages.live-server}/bin/live-server"
"--host=0.0.0.0"
"--port=6565"
"--quiet"
"--no-browser"
"--watch=%outputfile%"
"--entry-file=%outputfile%"
"--wait=800"
"/tmp"
]
else "firefox -new-window /tmp/%outputfile%";
in
# lua # lua
'' ''
-- --
@ -81,18 +110,18 @@ in {
markdownoutputext = 'html', markdownoutputext = 'html',
-- Markdown to PDF -- Markdown to PDF
mdtopdf = 'pandoc %docroot% -o /tmp/%outputfile%', mdtopdf = '${mdToPDF}',
markdowntopdf = 'pandoc %docroot% -o /tmp/%outputfile%', markdowntopdf = '${mdToPDF}',
mdtopdfviewerlaunch = 'sioyek /tmp/%outputfile%', mdtopdfviewerlaunch = '${mdToPDFViewer}',
markdowntopdfviewerlaunch = 'sioyek /tmp/%outputfile%', markdowntopdfviewerlaunch = '${mdToPDFViewer}',
mdtopdfviewerrefresh = 'none', mdtopdfviewerrefresh = 'none',
markdowntopdfviewerrefresh = "none", markdowntopdfviewerrefresh = 'none',
-- Markdown to HTML -- Markdown to HTML
mdtohtml = 'pandoc --standalone %docroot% -o /tmp/%outputfile%', mdtohtml = '${mdToHTML}',
markdowntohtml = 'pandoc --standalone %docroot% -o /tmp/%outputfile%', markdowntohtml = '${mdToHTML}',
mdtohtmlviewerlaunch = 'firefox -new-window /tmp/%outputfile%', mdtohtmlviewerlaunch = '${mdToHTMLViewer}',
markdowntohtmlviewerlaunch = 'firefox -new-window /tmp/%outputfile%', markdowntohtmlviewerlaunch = '${mdToHTMLViewer}',
mdtohtmlviewerrefresh = 'none', mdtohtmlviewerrefresh = 'none',
markdowntohtmlviewerrefresh = 'none', markdowntohtmlviewerrefresh = 'none',
@ -100,6 +129,13 @@ in {
-- TODO: stop from polluting workspace -- TODO: stop from polluting workspace
}; };
vim.api.nvim_create_autocmd('BufUnload', {
pattern = '*',
callback = function()
os.execute("killall -r live-server");
end,
});
-- F4 processes the document once, and refreshes the view -- F4 processes the document once, and refreshes the view
vim.keymap.set({ 'n', 'v', 'i' }, '<F4>', function() vim.keymap.set({ 'n', 'v', 'i' }, '<F4>', function()
require('knap').process_once(); require('knap').process_once();