Skip to content

Commit d55e698

Browse files
Konfektchrisbra
authored andcommitted
runtime(pandoc): refine pandoc compiler settings
closes: #15529 Signed-off-by: Christian Brabandt <cb@256bit.org> Signed-off-by: Konfekt <Konfekt@users.noreply.github.com>
1 parent 753794b commit d55e698

2 files changed

Lines changed: 33 additions & 22 deletions

File tree

runtime/compiler/pandoc.vim

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
" Vim compiler file
22
" Compiler: Pandoc
33
" Maintainer: Konfekt
4+
" Last Change: 2024 Aug 20
45
"
56
" Expects output file extension, say `:make html` or `:make pdf`.
67
" Passes additional arguments to pandoc, say `:make html --self-contained`.
@@ -25,31 +26,34 @@ let s:supported_filetypes =
2526

2627
silent! function s:PandocFiletype(filetype) abort
2728
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
39-
return ft
29+
30+
if ft ==# 'pandoc' | return 'markdown'
31+
elseif ft ==# 'tex' | return 'latex'
32+
" Pandoc does not support XML as a generic input format, but it does support
33+
" EndNote XML and Jats XML out of which the latter seems more universal.
34+
elseif ft ==# 'xml' | return 'jats'
35+
elseif ft ==# 'text' || empty(ft) | return 'markdown'
36+
elseif index(s:supported_filetypes, &ft) >= 0 | return ft
4037
else
41-
echomsg 'Unsupported filetype: ' . ft . ', falling back to Markdown as input format!'
38+
echomsg 'Unsupported filetype: '..ft..', falling back to Markdown as input format!'
4239
return 'markdown'
4340
endif
4441
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) .
49-
\ '\ ' . escape(get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')), ' ') .
50-
\ '\ --output\ %:r:S.$*\ %:S'
51-
52-
CompilerSet errorformat="%f",\ line\ %l:\ %m
42+
43+
let b:pandoc_compiler_from = get(b:, 'pandoc_compiler_from', s:PandocFiletype(&filetype))
44+
let b:pandoc_compiler_lang = get(b:, 'pandoc_compiler_lang', &spell ? matchstr(&spelllang, '^\a\a') : '')
45+
46+
execute 'CompilerSet makeprg=pandoc'..escape(
47+
\ ' --standalone' .
48+
\ (b:pandoc_compiler_from ==# 'markdown' && (getline(1) =~# '^%\s\+\S\+' || (search('^title:\s+\S+', 'cnw') > 0)) ?
49+
\ '' : ' --metadata title=%:t:r:S') .
50+
\ (empty(b:pandoc_compiler_lang) ?
51+
\ '' : ' --metadata lang='..b:pandoc_compiler_lang) .
52+
\ ' --from='..b:pandoc_compiler_from .
53+
\ ' '..get(b:, 'pandoc_compiler_args', get(g:, 'pandoc_compiler_args', '')) .
54+
\ ' --output %:r:S.$* -- %:S', ' ')
55+
56+
CompilerSet errorformat=%f,\ line\ %l:\ %m
5357

5458
let &cpo = s:keepcpo
5559
unlet s:keepcpo

runtime/doc/quickfix.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*quickfix.txt* For Vim version 9.1. Last change: 2024 Aug 05
1+
*quickfix.txt* For Vim version 9.1. Last change: 2024 Aug 20
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1345,6 +1345,13 @@ Additional arguments can be passed to pandoc:
13451345
- either by appending them to make, say `:make html --self-contained` .
13461346
- or setting them in `b:pandoc_compiler_args` or `g:pandoc_compiler_args`.
13471347

1348+
The `--from` argument is an educated guess using the buffer file type;
1349+
it can be overridden by setting `b:pandoc_compiler_from`.
1350+
Likewise the `--metadata lang` argument is set using `&spelllang`;
1351+
it can be overridden by setting `b:pandoc_compiler_lang`.
1352+
If `--from=markdown` is assumed and no title set in a title header or
1353+
YAML block, then the filename (without extension) is used as the title.
1354+
13481355
PERL *quickfix-perl* *compiler-perl*
13491356

13501357
The Perl compiler plugin doesn't actually compile, but invokes Perl's internal

0 commit comments

Comments
 (0)