blob: a536257eba8bf0df86e18ea1e2eb4e5ce297921d [file] [log] [blame]
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +02001" Vim compiler file
2" Compiler: Pandoc
3" Maintainer: Konfekt
4"
5" Expects output file extension, say `:make html` or `:make pdf`.
6" Passes additional arguments to pandoc, say `:make html --self-contained`.
7
8if exists("current_compiler")
9 finish
10endif
11
12if exists(":CompilerSet") != 2 " older Vim always used :setlocal
13 command -nargs=* CompilerSet setlocal <args>
14endif
15
16let s:keepcpo = &cpo
17set cpo&vim
18
19let current_compiler = 'pandoc'
20
21" As of 2024-04-08 pandoc supports the following text input formats with
22" an ftplugin on Github:
23let s:supported_filetypes =
24 \ [ 'bibtex', 'markdown', 'creole', 'json', 'csv', 'tsv', 'docbook',
25 \ 'xml', 'fb2', 'html', 'jira', 'tex', 'mediawiki', 'nroff', 'org',
26 \ 'rtf', 'rst', 't2t', 'textile', 'twiki', 'typst', 'vimwiki' ]
27" .. and out of those the following are included in Vim's runtime:
28" 'xml', 'tex', 'html', 'rst', 'json', 'nroff', 'markdown'
29
30silent! function s:PandocFiletype(filetype) abort
31 let ft = a:filetype
32 if ft ==# 'pandoc'
33 return 'markdown'
34 elseif ft ==# 'tex'
35 return 'latex'
36 elseif ft ==# 'xml'
37 " Pandoc does not support XML as a generic input format, but it does support
38 " EndNote XML and Jats XML out of which the latter seems more universal.
39 return 'jats'
40 elseif ft ==# 'text' || empty(ft)
41 return 'markdown'
42 elseif index(s:supported_filetypes, &ft) >= 0
43 return ft
44 else
45 echomsg 'Unsupported filetype: ' . a:filetype ', falling back to Markdown as input format!'
46 return 'markdown'
47 endif
48endfunction
49execute 'CompilerSet makeprg=pandoc\ --standalone' .
50 \ '\ --metadata\ title=%:t:r:S' .
51 \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') .
52 \ '\ --from=' . s:PandocFiletype(&filetype) .
53 \ '\ --output\ %:r:S.$*\ %:S'
54
55CompilerSet errorformat="%f",\ line\ %l:\ %m
56
57let &cpo = s:keepcpo
58unlet s:keepcpo