codekingpro/portable-devtools
114k
1" Vim compiler file2" Compiler: Pandoc3" Maintainer: Konfekt4" Last Change: 2024 Nov 195" 2025 May 15 by Vim Project: Update the title regex for CompilerSet #173216" 2026 Jan 10 by Vim Project: Do not set the title #190487"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 variable11" b/g:pandoc_compiler_args which defaults to empty.12 13if exists("current_compiler")14 finish15endif16 17let s:keepcpo = &cpo18set cpo&vim19 20let current_compiler = 'pandoc'21 22" As of 2024-04-08 pandoc supports the following text input formats with23" an ftplugin on Github:24let 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 31silent! function s:PandocFiletype(filetype) abort32 let ft = a:filetype33 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 support37 " 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 ft41 else42 echomsg 'Unsupported filetype: '..ft..', falling back to Markdown as input format!'43 return 'markdown'44 endif45endfunction46 47silent! function s:PandocLang()48 let lang = get(b:, 'pandoc_compiler_lang',49 \ &spell ? matchstr(&spelllang, '^\a\a') : '')50 if lang ==# 'en' | let lang = '' | endif51 return empty(lang) ? '' : '--metadata lang='..lang52endfunction53 54execute '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', ' \|"')60CompilerSet errorformat=\"%f\",\ line\ %l:\ %m61 62let &cpo = s:keepcpo63unlet s:keepcpo64 