refactor(compiler): resolve output before args
Problem: presets that need the output path in their args function (markdown, github) had to recompute it inline, duplicating the same gsub expression already in the output field. Solution: resolve output_file first in M.compile, then extend ctx with output = output_file into a resolved_ctx before evaluating args and cwd. Presets can now reference ctx.output directly. Add output? to the preview.Context type annotation.
This commit is contained in:
parent
4c22f84b31
commit
af8bb49122
4 changed files with 14 additions and 11 deletions
|
|
@ -138,8 +138,7 @@ M.markdown = {
|
|||
ft = 'markdown',
|
||||
cmd = { 'pandoc' },
|
||||
args = function(ctx)
|
||||
local output = ctx.file:gsub('%.md$', '.html')
|
||||
return { ctx.file, '-s', '--embed-resources', '-o', output }
|
||||
return { ctx.file, '-s', '--embed-resources', '-o', ctx.output }
|
||||
end,
|
||||
output = function(ctx)
|
||||
return (ctx.file:gsub('%.md$', '.html'))
|
||||
|
|
@ -158,7 +157,6 @@ M.github = {
|
|||
ft = 'markdown',
|
||||
cmd = { 'pandoc' },
|
||||
args = function(ctx)
|
||||
local output = ctx.file:gsub('%.md$', '.html')
|
||||
return {
|
||||
'-f',
|
||||
'gfm',
|
||||
|
|
@ -168,7 +166,7 @@ M.github = {
|
|||
'--css',
|
||||
'https://cdn.jsdelivr.net/gh/pixelbrackets/gfm-stylesheet@master/dist/gfm.css',
|
||||
'-o',
|
||||
output,
|
||||
ctx.output,
|
||||
}
|
||||
end,
|
||||
output = function(ctx)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue