Wu, Zhenyu | 7005b7e | 2024-04-08 20:53:19 +0200 | [diff] [blame] | 1 | " 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 | |
| 8 | if exists("current_compiler") |
| 9 | finish |
| 10 | endif |
| 11 | |
Wu, Zhenyu | 7005b7e | 2024-04-08 20:53:19 +0200 | [diff] [blame] | 12 | let s:keepcpo = &cpo |
| 13 | set cpo&vim |
| 14 | |
| 15 | let current_compiler = 'pandoc' |
| 16 | |
| 17 | " As of 2024-04-08 pandoc supports the following text input formats with |
| 18 | " an ftplugin on Github: |
| 19 | let 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 | |
| 26 | silent! 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 |
Enno | 6ce07ed | 2024-04-09 21:26:55 +0200 | [diff] [blame] | 39 | return ft |
Wu, Zhenyu | 7005b7e | 2024-04-08 20:53:19 +0200 | [diff] [blame] | 40 | else |
Enno | 6ce07ed | 2024-04-09 21:26:55 +0200 | [diff] [blame] | 41 | echomsg 'Unsupported filetype: ' . ft . ', falling back to Markdown as input format!' |
Wu, Zhenyu | 7005b7e | 2024-04-08 20:53:19 +0200 | [diff] [blame] | 42 | return 'markdown' |
| 43 | endif |
| 44 | endfunction |
| 45 | execute 'CompilerSet makeprg=pandoc\ --standalone' . |
| 46 | \ '\ --metadata\ title=%:t:r:S' . |
| 47 | \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') . |
| 48 | \ '\ --from=' . s:PandocFiletype(&filetype) . |
Konfekt | fb8f31e | 2024-04-15 19:33:08 +0200 | [diff] [blame] | 49 | \ '\ ' . escape(get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')), ' ') . |
Wu, Zhenyu | 7005b7e | 2024-04-08 20:53:19 +0200 | [diff] [blame] | 50 | \ '\ --output\ %:r:S.$*\ %:S' |
| 51 | |
| 52 | CompilerSet errorformat="%f",\ line\ %l:\ %m |
| 53 | |
| 54 | let &cpo = s:keepcpo |
| 55 | unlet s:keepcpo |