diff --git a/README.md b/README.md index 1c59fd6..80a2650 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # preview.nvim -**Universal previewer for Neovim** +**Universal document previewer for Neovim** An extensible framework for compiling and previewing _any_ documents (LaTeX, Typst, Markdown, etc.)—diagnostics included. diff --git a/doc/preview.txt b/doc/preview.txt index b4b74f5..383a8f5 100644 --- a/doc/preview.txt +++ b/doc/preview.txt @@ -68,10 +68,6 @@ 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. diff --git a/flake.nix b/flake.nix index f6c279b..636f4d0 100644 --- a/flake.nix +++ b/flake.nix @@ -19,8 +19,7 @@ { formatter = forEachSystem (pkgs: pkgs.nixfmt-tree); - devShells = forEachSystem ( - pkgs: + devShells = forEachSystem (pkgs: let devTools = [ (pkgs.luajit.withPackages ( @@ -51,7 +50,6 @@ pkgs.mermaid-cli ]; }; - } - ); + }); }; } diff --git a/lua/preview/compiler.lua b/lua/preview/compiler.lua index 3e8de12..a193ad2 100644 --- a/lua/preview/compiler.lua +++ b/lua/preview/compiler.lua @@ -309,9 +309,6 @@ 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 489679f..7cb982b 100644 --- a/lua/preview/init.lua +++ b/lua/preview/init.lua @@ -2,7 +2,6 @@ ---@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 @@ -95,7 +94,6 @@ 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) diff --git a/lua/preview/presets.lua b/lua/preview/presets.lua index d4b03cc..1b5333e 100644 --- a/lua/preview/presets.lua +++ b/lua/preview/presets.lua @@ -115,24 +115,6 @@ 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', @@ -331,7 +313,19 @@ M.mermaid = { return (ctx.file:gsub('%.mmd$', '.svg')) end, error_parser = function(output) - return parse_mermaid(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 end, clean = function(ctx) return { 'rm', '-f', (ctx.file:gsub('%.mmd$', '.svg')) }