aboutsummaryrefslogtreecommitdiff
path: root/runtime/compiler/pandoc.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/compiler/pandoc.vim')
-rw-r--r--runtime/compiler/pandoc.vim50
1 files changed, 29 insertions, 21 deletions
diff --git a/runtime/compiler/pandoc.vim b/runtime/compiler/pandoc.vim
index 6c151930c5..6c15e104c3 100644
--- a/runtime/compiler/pandoc.vim
+++ b/runtime/compiler/pandoc.vim
@@ -1,9 +1,12 @@
" Vim compiler file
" Compiler: Pandoc
" Maintainer: Konfekt
+" Last Change: 2024 Sep 8
"
" Expects output file extension, say `:make html` or `:make pdf`.
" Passes additional arguments to pandoc, say `:make html --self-contained`.
+" Adjust command-line flags by buffer-local/global variable
+" b/g:pandoc_compiler_args which defaults to empty.
if exists("current_compiler")
finish
@@ -25,31 +28,36 @@ let s:supported_filetypes =
silent! function s:PandocFiletype(filetype) abort
let ft = a:filetype
- if ft ==# 'pandoc'
- return 'markdown'
- elseif ft ==# 'tex'
- return 'latex'
- elseif ft ==# 'xml'
- " Pandoc does not support XML as a generic input format, but it does support
- " EndNote XML and Jats XML out of which the latter seems more universal.
- return 'jats'
- elseif ft ==# 'text' || empty(ft)
- return 'markdown'
- elseif index(s:supported_filetypes, &ft) >= 0
- return ft
+
+ if ft ==# 'pandoc' | return 'markdown'
+ elseif ft ==# 'tex' | return 'latex'
+ " Pandoc does not support XML as a generic input format, but it does support
+ " EndNote XML and Jats XML out of which the latter seems more universal.
+ elseif ft ==# 'xml' | return 'jats'
+ elseif ft ==# 'text' || empty(ft) | return 'markdown'
+ elseif index(s:supported_filetypes, &ft) >= 0 | return ft
else
- echomsg 'Unsupported filetype: ' . ft . ', falling back to Markdown as input format!'
+ echomsg 'Unsupported filetype: '..ft..', falling back to Markdown as input format!'
return 'markdown'
endif
endfunction
-execute 'CompilerSet makeprg=pandoc\ --standalone' .
- \ '\ --metadata\ title=%:t:r:S' .
- \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') .
- \ '\ --from=' . s:PandocFiletype(&filetype) .
- \ '\ ' . escape(get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')), ' ') .
- \ '\ --output\ %:r:S.$*\ %:S'
-
-CompilerSet errorformat="%f",\ line\ %l:\ %m
+
+silent! function s:PandocLang()
+ let lang = get(b:, 'pandoc_compiler_lang',
+ \ &spell ? matchstr(&spelllang, '^\a\a') : '')
+ if lang ==# 'en' | let lang = '' | endif
+ return empty(lang) ? '' : '--metadata lang='..lang
+endfunction
+
+execute 'CompilerSet makeprg=pandoc'..escape(
+ \ ' --standalone'..
+ \ (s:PandocFiletype(&filetype) ==# 'markdown' && (getline(1) =~# '^%\s\+\S\+' || (search('^title:\s+\S+', 'cnw') > 0)) ?
+ \ '' : ' --metadata title=%:t:r:S')..
+ \ ' '..s:PandocLang()..
+ \ ' --from='..s:PandocFiletype(&filetype)..
+ \ ' '..get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', ''))..
+ \ ' --output %:r:S.$* -- %:S', ' ')
+CompilerSet errorformat=\"%f\",\ line\ %l:\ %m
let &cpo = s:keepcpo
unlet s:keepcpo