aboutsummaryrefslogtreecommitdiff
path: root/runtime/compiler/pandoc.vim
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2024-04-08 22:42:54 +0200
committerChristian Clason <c.clason@uni-graz.at>2024-04-09 10:24:49 +0200
commit41521658b1dca302a4c7125753694b59a317c0f9 (patch)
tree57017c3029dd16d596053dcc9f32497fe838aaa6 /runtime/compiler/pandoc.vim
parent168e69ae0156e2b59e1d44b6cadbf7359d5285e9 (diff)
downloadrneovim-41521658b1dca302a4c7125753694b59a317c0f9.tar.gz
rneovim-41521658b1dca302a4c7125753694b59a317c0f9.tar.bz2
rneovim-41521658b1dca302a4c7125753694b59a317c0f9.zip
vim-patch:9.1.0276: No pandoc syntax support
Problem: No pandoc syntax support Solution: Add pandoc syntax and compiler plugins (Wu, Zhenyu, Konfekt) closes: vim/vim#14389 https://github.com/vim/vim/commit/7005b7ee7f282b24378c2a844366cb8616cad5d7 Co-authored-by: Wu, Zhenyu <wuzhenyu@ustc.edu> Co-authored-by: Konfekt <Konfekt@users.noreply.github.com>
Diffstat (limited to 'runtime/compiler/pandoc.vim')
-rw-r--r--runtime/compiler/pandoc.vim58
1 files changed, 58 insertions, 0 deletions
diff --git a/runtime/compiler/pandoc.vim b/runtime/compiler/pandoc.vim
new file mode 100644
index 0000000000..a536257eba
--- /dev/null
+++ b/runtime/compiler/pandoc.vim
@@ -0,0 +1,58 @@
+" Vim compiler file
+" Compiler: Pandoc
+" Maintainer: Konfekt
+"
+" Expects output file extension, say `:make html` or `:make pdf`.
+" Passes additional arguments to pandoc, say `:make html --self-contained`.
+
+if exists("current_compiler")
+ finish
+endif
+
+if exists(":CompilerSet") != 2 " older Vim always used :setlocal
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+let s:keepcpo = &cpo
+set cpo&vim
+
+let current_compiler = 'pandoc'
+
+" As of 2024-04-08 pandoc supports the following text input formats with
+" an ftplugin on Github:
+let s:supported_filetypes =
+ \ [ 'bibtex', 'markdown', 'creole', 'json', 'csv', 'tsv', 'docbook',
+ \ 'xml', 'fb2', 'html', 'jira', 'tex', 'mediawiki', 'nroff', 'org',
+ \ 'rtf', 'rst', 't2t', 'textile', 'twiki', 'typst', 'vimwiki' ]
+" .. and out of those the following are included in Vim's runtime:
+" 'xml', 'tex', 'html', 'rst', 'json', 'nroff', 'markdown'
+
+silent! function s:PandocFiletype(filetype) abort
+ let ft = a:filetype
+ if ft ==# 'pandoc'
+ return 'markdown'
+ elseif ft ==# 'tex'
+ return 'latex'
+ elseif ft ==# 'xml'
+ " Pandoc does not support XML as a generic input format, but it does support
+ " EndNote XML and Jats XML out of which the latter seems more universal.
+ return 'jats'
+ elseif ft ==# 'text' || empty(ft)
+ return 'markdown'
+ elseif index(s:supported_filetypes, &ft) >= 0
+ return ft
+ else
+ echomsg 'Unsupported filetype: ' . a:filetype ', falling back to Markdown as input format!'
+ return 'markdown'
+ endif
+endfunction
+execute 'CompilerSet makeprg=pandoc\ --standalone' .
+ \ '\ --metadata\ title=%:t:r:S' .
+ \ '\ --metadata\ lang=' . matchstr(&spelllang, '^\a\a') .
+ \ '\ --from=' . s:PandocFiletype(&filetype) .
+ \ '\ --output\ %:r:S.$*\ %:S'
+
+CompilerSet errorformat="%f",\ line\ %l:\ %m
+
+let &cpo = s:keepcpo
+unlet s:keepcpo