pandoc.vim (2290B)
1 " Vim compiler file 2 " Compiler: Pandoc 3 " Maintainer: Konfekt 4 " Last Change: 2024 Nov 19 5 " 2025 May 15 by Vim Project: Update the title regex for CompilerSet #17321 6 " 2026 Jan 10 by Vim Project: Do not set the title #19048 7 " 8 " Expects output file extension, say `:make html` or `:make pdf`. 9 " Passes additional arguments to pandoc, say `:make html --self-contained`. 10 " Adjust command-line flags by buffer-local/global variable 11 " b/g:pandoc_compiler_args which defaults to empty. 12 13 if exists("current_compiler") 14 finish 15 endif 16 17 let s:keepcpo = &cpo 18 set cpo&vim 19 20 let current_compiler = 'pandoc' 21 22 " As of 2024-04-08 pandoc supports the following text input formats with 23 " an ftplugin on Github: 24 let s:supported_filetypes = 25 \ [ 'bibtex', 'markdown', 'creole', 'json', 'csv', 'tsv', 'docbook', 26 \ 'xml', 'fb2', 'html', 'jira', 'tex', 'mediawiki', 'nroff', 'org', 27 \ 'rtf', 'rst', 't2t', 'textile', 'twiki', 'typst', 'vimwiki' ] 28 " .. and out of those the following are included in Vim's runtime: 29 " 'xml', 'tex', 'html', 'rst', 'json', 'nroff', 'markdown' 30 31 silent! function s:PandocFiletype(filetype) abort 32 let ft = a:filetype 33 34 if ft ==# 'pandoc' | return 'markdown' 35 elseif ft ==# 'tex' | return 'latex' 36 " Pandoc does not support XML as a generic input format, but it does support 37 " EndNote XML and Jats XML out of which the latter seems more universal. 38 elseif ft ==# 'xml' | return 'jats' 39 elseif ft ==# 'text' || empty(ft) | return 'markdown' 40 elseif index(s:supported_filetypes, &ft) >= 0 | return ft 41 else 42 echomsg 'Unsupported filetype: '..ft..', falling back to Markdown as input format!' 43 return 'markdown' 44 endif 45 endfunction 46 47 silent! function s:PandocLang() 48 let lang = get(b:, 'pandoc_compiler_lang', 49 \ &spell ? matchstr(&spelllang, '^\a\a') : '') 50 if lang ==# 'en' | let lang = '' | endif 51 return empty(lang) ? '' : '--metadata lang='..lang 52 endfunction 53 54 execute 'CompilerSet makeprg=pandoc'..escape( 55 \ ' --standalone'.. 56 \ ' '..s:PandocLang().. 57 \ ' --from='..s:PandocFiletype(&filetype).. 58 \ ' '..get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')).. 59 \ ' --output %:r:S.$* -- %:S', ' \|"') 60 CompilerSet errorformat=\"%f\",\ line\ %l:\ %m 61 62 let &cpo = s:keepcpo 63 unlet s:keepcpo