feat(presets): add pdflatex, tectonic, asciidoctor, and quarto presets (#30)
* feat(presets): add pdflatex preset Adds a direct pdflatex preset for users who want single-pass compilation without latexmk orchestration. Uses -file-line-error for parseable diagnostics and reuses the existing parse_latexmk error parser since both emit the same file:line: message format. * feat(presets): add tectonic preset Adds a tectonic preset for the modern Rust-based LaTeX engine, which auto-downloads packages and requires no TeX installation. Reuses parse_latexmk since tectonic emits the same file:line: message diagnostic format. * feat(presets): add asciidoctor preset Adds an asciidoctor preset for AsciiDoc → HTML compilation with SSE live-reload. Includes a parse_asciidoctor error parser handling the "asciidoctor: SEVERITY: file: line N: message" format for both ERROR and WARNING diagnostics. * feat(presets): add quarto preset Adds a quarto preset for .qmd scientific documents rendering to self-contained HTML with SSE live-reload. Uses --embed-resources to avoid a _files directory in the common case. No error_parser since quarto errors are heterogeneous (mixed R/Python/pandoc output). * refactor: apply stylua formatting to new preset code
This commit is contained in:
parent
c94df7c5d0
commit
180c672983
3 changed files with 314 additions and 0 deletions
|
|
@ -93,6 +93,28 @@ local function parse_pandoc(output)
|
|||
return diagnostics
|
||||
end
|
||||
|
||||
---@param output string
|
||||
---@return preview.Diagnostic[]
|
||||
local function parse_asciidoctor(output)
|
||||
local diagnostics = {}
|
||||
for line in output:gmatch('[^\r\n]+') do
|
||||
local severity, _, lnum, msg = line:match('^asciidoctor: (%u+): (.+): line (%d+): (.+)$')
|
||||
if lnum then
|
||||
local sev = vim.diagnostic.severity.ERROR
|
||||
if severity == 'WARNING' then
|
||||
sev = vim.diagnostic.severity.WARN
|
||||
end
|
||||
table.insert(diagnostics, {
|
||||
lnum = tonumber(lnum) - 1,
|
||||
col = 0,
|
||||
message = msg,
|
||||
severity = sev,
|
||||
})
|
||||
end
|
||||
end
|
||||
return diagnostics
|
||||
end
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.typst = {
|
||||
ft = 'typst',
|
||||
|
|
@ -137,6 +159,38 @@ M.latex = {
|
|||
open = true,
|
||||
}
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.pdflatex = {
|
||||
ft = 'tex',
|
||||
cmd = { 'pdflatex' },
|
||||
args = function(ctx)
|
||||
return { '-interaction=nonstopmode', '-file-line-error', '-synctex=1', ctx.file }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return (ctx.file:gsub('%.tex$', '.pdf'))
|
||||
end,
|
||||
error_parser = function(output)
|
||||
return parse_latexmk(output)
|
||||
end,
|
||||
open = true,
|
||||
}
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.tectonic = {
|
||||
ft = 'tex',
|
||||
cmd = { 'tectonic' },
|
||||
args = function(ctx)
|
||||
return { ctx.file }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return (ctx.file:gsub('%.tex$', '.pdf'))
|
||||
end,
|
||||
error_parser = function(output)
|
||||
return parse_latexmk(output)
|
||||
end,
|
||||
open = true,
|
||||
}
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.markdown = {
|
||||
ft = 'markdown',
|
||||
|
|
@ -187,4 +241,42 @@ M.github = {
|
|||
reload = true,
|
||||
}
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.asciidoctor = {
|
||||
ft = 'asciidoc',
|
||||
cmd = { 'asciidoctor' },
|
||||
args = function(ctx)
|
||||
return { ctx.file, '-o', ctx.output }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return (ctx.file:gsub('%.adoc$', '.html'))
|
||||
end,
|
||||
error_parser = function(output)
|
||||
return parse_asciidoctor(output)
|
||||
end,
|
||||
clean = function(ctx)
|
||||
return { 'rm', '-f', (ctx.file:gsub('%.adoc$', '.html')) }
|
||||
end,
|
||||
open = true,
|
||||
reload = true,
|
||||
}
|
||||
|
||||
---@type preview.ProviderConfig
|
||||
M.quarto = {
|
||||
ft = 'quarto',
|
||||
cmd = { 'quarto' },
|
||||
args = function(ctx)
|
||||
return { 'render', ctx.file, '--to', 'html', '--embed-resources' }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return (ctx.file:gsub('%.qmd$', '.html'))
|
||||
end,
|
||||
clean = function(ctx)
|
||||
local base = ctx.file:gsub('%.qmd$', '')
|
||||
return { 'rm', '-rf', base .. '.html', base .. '_files' }
|
||||
end,
|
||||
open = true,
|
||||
reload = true,
|
||||
}
|
||||
|
||||
return M
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue