blob: 6c151930c5c0c87a67b0de27e8267f623ccf296f [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
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +020012let s:keepcpo = &cpo
13set cpo&vim
14
15let current_compiler = 'pandoc'
16
17" As of 2024-04-08 pandoc supports the following text input formats with
18" an ftplugin on Github:
19let s:supported_filetypes =
20 \ [ 'bibtex', 'markdown', 'creole', 'json', 'csv', 'tsv', 'docbook',
21 \ 'xml', 'fb2', 'html', 'jira', 'tex', 'mediawiki', 'nroff', 'org',
22 \ 'rtf', 'rst', 't2t', 'textile', 'twiki', 'typst', 'vimwiki' ]
23" .. and out of those the following are included in Vim's runtime:
24" 'xml', 'tex', 'html', 'rst', 'json', 'nroff', 'markdown'
25
26silent! function s:PandocFiletype(filetype) abort
27 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
Enno6ce07ed2024-04-09 21:26:55 +020039 return ft
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +020040 else
Enno6ce07ed2024-04-09 21:26:55 +020041 echomsg 'Unsupported filetype: ' . ft . ', falling back to Markdown as input format!'
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +020042 return 'markdown'
43 endif
44endfunction
45execute 'CompilerSet makeprg=pandoc\ --standalone' .
46 \ '\ --metadata\ title=%:t:r:S' .
47 \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') .
48 \ '\ --from=' . s:PandocFiletype(&filetype) .
Konfektfb8f31e2024-04-15 19:33:08 +020049 \ '\ ' . escape(get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')), ' ') .
Wu, Zhenyu7005b7e2024-04-08 20:53:19 +020050 \ '\ --output\ %:r:S.$*\ %:S'
51
52CompilerSet errorformat="%f",\ line\ %l:\ %m
53
54let &cpo = s:keepcpo
55unlet s:keepcpo