11" Vim compiler file
22" Compiler: Pandoc
33" Maintainer: Konfekt
4+ " Last Change: 2024 Aug 20
45"
56" Expects output file extension, say `:make html` or `:make pdf`.
67" Passes additional arguments to pandoc, say `:make html --self-contained`.
@@ -25,31 +26,34 @@ let s:supported_filetypes =
2526
2627silent ! function s: PandocFiletype (filetype ) abort
2728 let ft = a: filetype
28- if ft == # ' pandoc'
29- return ' markdown'
30- elseif ft == # ' tex'
31- return ' latex'
32- elseif ft == # ' xml'
33- " Pandoc does not support XML as a generic input format, but it does support
34- " EndNote XML and Jats XML out of which the latter seems more universal.
35- return ' jats'
36- elseif ft == # ' text' || empty (ft )
37- return ' markdown'
38- elseif index (s: supported_filetypes , &ft ) >= 0
39- return ft
29+
30+ if ft == # ' pandoc' | return ' markdown'
31+ elseif ft == # ' tex' | return ' latex'
32+ " Pandoc does not support XML as a generic input format, but it does support
33+ " EndNote XML and Jats XML out of which the latter seems more universal.
34+ elseif ft == # ' xml' | return ' jats'
35+ elseif ft == # ' text' || empty (ft ) | return ' markdown'
36+ elseif index (s: supported_filetypes , &ft ) >= 0 | return ft
4037 else
41- echomsg ' Unsupported filetype: ' . ft . ' , falling back to Markdown as input format!'
38+ echomsg ' Unsupported filetype: ' .. ft .. ' , falling back to Markdown as input format!'
4239 return ' markdown'
4340 endif
4441endfunction
45- execute ' CompilerSet makeprg=pandoc\ --standalone' .
46- \ ' \ --metadata\ title=%:t:r:S' .
47- \ ' \ --metadata\ lang=' . matchstr (&spelllang , ' ^\a\a' ) .
48- \ ' \ --from=' . s: PandocFiletype (&filetype ) .
49- \ ' \ ' . escape (get (b: , ' pandoc_compiler_args' , get (g: , ' pandoc_compiler_args' , ' ' )), ' ' ) .
50- \ ' \ --output\ %:r:S.$*\ %:S'
51-
52- CompilerSet errorformat = " %f" ,\ line \ % l: \ % m
42+
43+ let b: pandoc_compiler_from = get (b: , ' pandoc_compiler_from' , s: PandocFiletype (&filetype ))
44+ let b: pandoc_compiler_lang = get (b: , ' pandoc_compiler_lang' , &spell ? matchstr (&spelllang , ' ^\a\a' ) : ' ' )
45+
46+ execute ' CompilerSet makeprg=pandoc' ..escape (
47+ \ ' --standalone' .
48+ \ (b: pandoc_compiler_from == # ' markdown' && (getline (1 ) = ~# ' ^%\s\+\S\+' || (search (' ^title:\s+\S+' , ' cnw' ) > 0 )) ?
49+ \ ' ' : ' --metadata title=%:t:r:S' ) .
50+ \ (empty (b: pandoc_compiler_lang ) ?
51+ \ ' ' : ' --metadata lang=' ..b: pandoc_compiler_lang ) .
52+ \ ' --from=' ..b: pandoc_compiler_from .
53+ \ ' ' ..get (b: , ' pandoc_compiler_args' , get (g: , ' pandoc_compiler_args' , ' ' )) .
54+ \ ' --output %:r:S.$* -- %:S' , ' ' )
55+
56+ CompilerSet errorformat = % f ,\ line \ % l: \ % m
5357
5458let &cpo = s: keepcpo
5559unlet s: keepcpo
0 commit comments