From 6f090fdcf33155cb116b898109c6dcaa106e6e4a Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 10:55:03 -0500 Subject: [PATCH 1/6] build: split nix dev shell into `default` and `presets` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: the single dev shell mixed dev tooling (linters, test runner) with preset compiler tools, causing heavy rebuilds (e.g. Chromium for `mermaid-cli`) for contributors who only need the dev tools. Solution: extract dev tooling into a shared `devTools` list and expose two shells — `default` for development and `presets` for running all built-in preset compilers (`typst`, `texliveMedium`, `tectonic`, `pandoc`, `asciidoctor`, `quarto`, `plantuml`, `mermaid-cli`). --- flake.nix | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 4ae4479..636f4d0 100644 --- a/flake.nix +++ b/flake.nix @@ -19,9 +19,9 @@ { formatter = forEachSystem (pkgs: pkgs.nixfmt-tree); - devShells = forEachSystem (pkgs: { - default = pkgs.mkShell { - packages = [ + devShells = forEachSystem (pkgs: + let + devTools = [ (pkgs.luajit.withPackages ( ps: with ps; [ busted @@ -32,9 +32,24 @@ pkgs.stylua pkgs.selene pkgs.lua-language-server - pkgs.plantuml ]; - }; - }); + in + { + default = pkgs.mkShell { + packages = devTools; + }; + presets = pkgs.mkShell { + packages = devTools ++ [ + pkgs.typst + pkgs.texliveMedium + pkgs.tectonic + pkgs.pandoc + pkgs.asciidoctor + pkgs.quarto + pkgs.plantuml + pkgs.mermaid-cli + ]; + }; + }); }; } From 8c9847e321bf277e5f8de8d7b7eca6a17dd86b8e Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Thu, 5 Mar 2026 11:05:16 -0500 Subject: [PATCH 2/6] build: split nix dev shell into `default` and `presets` (#48) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: the single dev shell mixed dev tooling (linters, test runner) with preset compiler tools, causing heavy rebuilds (e.g. Chromium for `mermaid-cli`) for contributors who only need the dev tools. Solution: extract dev tooling into a shared `devTools` list and expose two shells — `default` for development and `presets` for running all built-in preset compilers (`typst`, `texliveMedium`, `tectonic`, `pandoc`, `asciidoctor`, `quarto`, `plantuml`, `mermaid-cli`). --- flake.nix | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index d5bdae4..636f4d0 100644 --- a/flake.nix +++ b/flake.nix @@ -19,9 +19,9 @@ { formatter = forEachSystem (pkgs: pkgs.nixfmt-tree); - devShells = forEachSystem (pkgs: { - default = pkgs.mkShell { - packages = [ + devShells = forEachSystem (pkgs: + let + devTools = [ (pkgs.luajit.withPackages ( ps: with ps; [ busted @@ -32,10 +32,24 @@ pkgs.stylua pkgs.selene pkgs.lua-language-server - pkgs.plantuml - pkgs.mermaid-cli ]; - }; - }); + in + { + default = pkgs.mkShell { + packages = devTools; + }; + presets = pkgs.mkShell { + packages = devTools ++ [ + pkgs.typst + pkgs.texliveMedium + pkgs.tectonic + pkgs.pandoc + pkgs.asciidoctor + pkgs.quarto + pkgs.plantuml + pkgs.mermaid-cli + ]; + }; + }); }; } From 00caad18bfb2196fd6ed79a95315d0a4a5b5af82 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Thu, 5 Mar 2026 12:05:34 -0500 Subject: [PATCH 3/6] refactor(presets): simplify `mermaid` error parser (#49) * feat: add `mermaid` preset Problem: no built-in support for compiling mermaid diagrams via `mmdc`. Solution: add a `mermaid` preset that compiles `.mmd` files to SVG and parses `Parse error on line N` diagnostics from stderr. Add `mermaid-cli` to the nix dev shell. * refactor(presets): simplify `mermaid` error parser Problem: the inline `mermaid` error_parser looped over every line and used the `Parse error on line N:` header as the message, losing the useful `Expecting ..., got ...` token detail. Solution: extract `parse_mermaid` alongside the other parse functions, use a single `output:match` (mermaid's JISON parser stops at the first error), and surface the `Expecting ..., got ...` line as the message. * ci: format * ci: format --- flake.nix | 6 ++++-- lua/preview/presets.lua | 32 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/flake.nix b/flake.nix index 636f4d0..f6c279b 100644 --- a/flake.nix +++ b/flake.nix @@ -19,7 +19,8 @@ { formatter = forEachSystem (pkgs: pkgs.nixfmt-tree); - devShells = forEachSystem (pkgs: + devShells = forEachSystem ( + pkgs: let devTools = [ (pkgs.luajit.withPackages ( @@ -50,6 +51,7 @@ pkgs.mermaid-cli ]; }; - }); + } + ); }; } diff --git a/lua/preview/presets.lua b/lua/preview/presets.lua index 1b5333e..d4b03cc 100644 --- a/lua/preview/presets.lua +++ b/lua/preview/presets.lua @@ -115,6 +115,24 @@ local function parse_asciidoctor(output) return diagnostics end +---@param output string +---@return preview.Diagnostic[] +local function parse_mermaid(output) + local lnum = output:match('Parse error on line (%d+)') + if not lnum then + return {} + end + local msg = output:match('(Expecting .+)') or 'parse error' + return { + { + lnum = tonumber(lnum) - 1, + col = 0, + message = msg, + severity = vim.diagnostic.severity.ERROR, + }, + } +end + ---@type preview.ProviderConfig M.typst = { ft = 'typst', @@ -313,19 +331,7 @@ M.mermaid = { return (ctx.file:gsub('%.mmd$', '.svg')) end, error_parser = function(output) - local diagnostics = {} - for line in output:gmatch('[^\r\n]+') do - local lnum = line:match('^%s*Parse error on line (%d+)') - if lnum then - table.insert(diagnostics, { - lnum = tonumber(lnum) - 1, - col = 0, - message = line, - severity = vim.diagnostic.severity.ERROR, - }) - end - end - return diagnostics + return parse_mermaid(output) end, clean = function(ctx) return { 'rm', '-f', (ctx.file:gsub('%.mmd$', '.svg')) } From 1fbc307badcad1454d65694b673cc986c94cf697 Mon Sep 17 00:00:00 2001 From: Barrett Ruth <62671086+barrettruth@users.noreply.github.com> Date: Thu, 5 Mar 2026 15:24:52 -0500 Subject: [PATCH 4/6] Update README to refine project description --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 80a2650..1c59fd6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # preview.nvim -**Universal document previewer for Neovim** +**Universal previewer for Neovim** An extensible framework for compiling and previewing _any_ documents (LaTeX, Typst, Markdown, etc.)—diagnostics included. From 7f1f8f8d65772156d9e34ca63f5a28883182c82e Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 22:05:36 -0500 Subject: [PATCH 5/6] feat: add `extra_args` provider field Problem: Overriding a single flag (e.g. `-outdir=build`) required redefining the entire `args` function, duplicating all preset defaults. Solution: Add `extra_args` field that appends to the resolved `args` after evaluation. Accepts a static table or a context function. --- lua/preview/compiler.lua | 3 +++ lua/preview/init.lua | 2 ++ 2 files changed, 5 insertions(+) diff --git a/lua/preview/compiler.lua b/lua/preview/compiler.lua index a193ad2..3e8de12 100644 --- a/lua/preview/compiler.lua +++ b/lua/preview/compiler.lua @@ -309,6 +309,9 @@ function M.compile(bufnr, name, provider, ctx, opts) if provider.args then vim.list_extend(cmd, eval_list(provider.args, resolved_ctx)) end + if provider.extra_args then + vim.list_extend(cmd, eval_list(provider.extra_args, resolved_ctx)) + end log.dbg('compiling buffer %d with provider "%s": %s', bufnr, name, table.concat(cmd, ' ')) diff --git a/lua/preview/init.lua b/lua/preview/init.lua index 7cb982b..489679f 100644 --- a/lua/preview/init.lua +++ b/lua/preview/init.lua @@ -2,6 +2,7 @@ ---@field ft? string ---@field cmd string[] ---@field args? string[]|fun(ctx: preview.Context): string[] +---@field extra_args? string[]|fun(ctx: preview.Context): string[] ---@field cwd? string|fun(ctx: preview.Context): string ---@field env? table ---@field output? string|fun(ctx: preview.Context): string @@ -94,6 +95,7 @@ function M.setup(opts) vim.validate(prefix .. '.cmd', provider.cmd, 'table') vim.validate(prefix .. '.cmd[1]', provider.cmd[1], 'string') vim.validate(prefix .. '.args', provider.args, { 'table', 'function' }, true) + vim.validate(prefix .. '.extra_args', provider.extra_args, { 'table', 'function' }, true) vim.validate(prefix .. '.cwd', provider.cwd, { 'string', 'function' }, true) vim.validate(prefix .. '.output', provider.output, { 'string', 'function' }, true) vim.validate(prefix .. '.error_parser', provider.error_parser, 'function', true) From 3b15ed7c6cc71e3455c1b8ab3123b1964f94ddf9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Thu, 5 Mar 2026 22:07:53 -0500 Subject: [PATCH 6/6] docs: document `extra_args` provider field --- doc/preview.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/doc/preview.txt b/doc/preview.txt index 383a8f5..b4b74f5 100644 --- a/doc/preview.txt +++ b/doc/preview.txt @@ -68,6 +68,10 @@ Provider fields: ~ receives a |preview.Context| and returns a string[]. + {extra_args} (string[]|function) Appended to {args} after evaluation. + Useful for adding flags to a preset + without replacing its defaults. + {cwd} (string|function) Working directory. If a function, receives a |preview.Context|. Default: git root or file directory.