pandoc.vim 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if exists("current_compiler")
  8. finish
  9. endif
  10. let s:keepcpo = &cpo
  11. set cpo&vim
  12. let current_compiler = 'pandoc'
  13. " As of 2024-04-08 pandoc supports the following text input formats with
  14. " an ftplugin on Github:
  15. let s:supported_filetypes =
  16. \ [ 'bibtex', 'markdown', 'creole', 'json', 'csv', 'tsv', 'docbook',
  17. \ 'xml', 'fb2', 'html', 'jira', 'tex', 'mediawiki', 'nroff', 'org',
  18. \ 'rtf', 'rst', 't2t', 'textile', 'twiki', 'typst', 'vimwiki' ]
  19. " .. and out of those the following are included in Vim's runtime:
  20. " 'xml', 'tex', 'html', 'rst', 'json', 'nroff', 'markdown'
  21. silent! function s:PandocFiletype(filetype) abort
  22. let ft = a:filetype
  23. if ft ==# 'pandoc'
  24. return 'markdown'
  25. elseif ft ==# 'tex'
  26. return 'latex'
  27. elseif ft ==# 'xml'
  28. " Pandoc does not support XML as a generic input format, but it does support
  29. " EndNote XML and Jats XML out of which the latter seems more universal.
  30. return 'jats'
  31. elseif ft ==# 'text' || empty(ft)
  32. return 'markdown'
  33. elseif index(s:supported_filetypes, &ft) >= 0
  34. return ft
  35. else
  36. echomsg 'Unsupported filetype: ' . ft . ', falling back to Markdown as input format!'
  37. return 'markdown'
  38. endif
  39. endfunction
  40. execute 'CompilerSet makeprg=pandoc\ --standalone' .
  41. \ '\ --metadata\ title=%:t:r:S' .
  42. \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') .
  43. \ '\ --from=' . s:PandocFiletype(&filetype) .
  44. \ '\ ' . escape(get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')), ' ') .
  45. \ '\ --output\ %:r:S.$*\ %:S'
  46. CompilerSet errorformat="%f",\ line\ %l:\ %m
  47. let &cpo = s:keepcpo
  48. unlet s:keepcpo