diff options
| author | jdhao <jdhao@hotmail.com> | 2022-07-19 01:18:26 +0800 |
|---|---|---|
| committer | jdhao <jdhao@hotmail.com> | 2022-07-19 01:18:26 +0800 |
| commit | 33270f32579672e43c8b6f8d5b64ef0e4e99d20e (patch) | |
| tree | 14251aacf36e9d5810d9cd002fa9be7756faee9f /plugin/command.vim | |
| parent | 99d5a0343b288ec82dc4e43ee5c689c5f5b31960 (diff) | |
add command ToPDF
Diffstat (limited to 'plugin/command.vim')
| -rw-r--r-- | plugin/command.vim | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/plugin/command.vim b/plugin/command.vim index d751831..5ed7b73 100644 --- a/plugin/command.vim +++ b/plugin/command.vim @@ -8,3 +8,40 @@ call utils#Cabbrev('man', 'Man') " show current date and time in human readable format command! -nargs=? Datetime echo utils#iso_time(<q-args>) + +" Convert Markdown file to PDF +command! ToPDF call s:md_to_pdf() + +function! s:md_to_pdf() abort + " check if pandoc is installed + if executable('pandoc') != 1 + echoerr "pandoc not found" + return + endif + + let l:md_path = expand("%:p") + let l:pdf_path = fnamemodify(l:md_path, ":r") .. ".pdf" + + let l:header_path = stdpath('config') . '/resources/head.tex' + + let l:cmd = "pandoc --pdf-engine=xelatex --highlight-style=zenburn --table-of-content " . + \ "--include-in-header=" . l:header_path . " -V fontsize=10pt -V colorlinks -V toccolor=NavyBlue " . + \ "-V linkcolor=red -V urlcolor=teal -V filecolor=magenta -s " . + \ l:md_path . " -o " . l:pdf_path + + if g:is_mac + let l:cmd = l:cmd . '&& open ' . l:pdf_path + endif + + if g:is_win + let l:cmd = l:cmd . '&& start ' . l:pdf_path + endif + + " echomsg l:cmd + + let l:id = jobstart(l:cmd) + + if l:id == 0 || l:id == -1 + echoerr "Error running command" + endif +endfunction |
