Revision | 81a17217b749fc4f3f66a462922427bfe442ec89 (tree) |
---|---|
Time | 2023-04-26 18:30:02 |
Author | badcoff33 <none@none> |
Commiter | badcoff33 |
avoid error message in case no file exists
@@ -14,21 +14,26 @@ else | ||
14 | 14 | let b:markdown_template_file = " --template=" .. b:markdown_template_file |
15 | 15 | endif |
16 | 16 | |
17 | -let b:markdown_command = "pandoc -f gfm -t html5 --toc --toc-depth=3" | |
18 | - \ .. b:markdown_css_file | |
19 | - \ .. b:markdown_template_file | |
20 | - \ .." --metadata title=\""..expand("%:t:r").."\"" | |
21 | - \ .." -o "..getenv("TEMP")..g:slash..expand("%:t")..".html" | |
22 | - \ .." "..getenv("TEMP")..g:slash.."_"..expand("%:t") | |
23 | 17 | |
24 | 18 | function! s:OpenHTML() |
25 | - exe "terminal ++close ++hidden cmd /C start" getenv("TEMP")..g:slash..expand("%:t")..".html" | |
19 | + exe "terminal ++close ++hidden cmd /C start" getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
20 | +endfunction | |
21 | + | |
22 | +function! s:ComputeCommand(file) | |
23 | + return "pandoc -f gfm -t html5 --toc --toc-depth=3" | |
24 | + \ .. b:markdown_css_file | |
25 | + \ .. b:markdown_template_file | |
26 | + \ .. " --metadata title=\"" .. expand("%:t:r") .. "\"" | |
27 | + \ .. " -o " .. getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
28 | + \ .. " " .. getenv("TEMP") .. g:slash.."_" .. expand("%:t") | |
26 | 29 | endfunction |
27 | 30 | |
28 | 31 | function! s:MakeHTML(...) |
29 | - if exists("b:markdown_command") | |
30 | - silent exe "write!" getenv("TEMP")..g:slash.."_"..expand("%:t") | |
31 | - silent exe "bwipeout!" getenv("TEMP")..g:slash.."_"..expand("%:t") | |
32 | + if filereadable(expand("%")) | |
33 | + let b:markdown_command = s:ComputeCommand(expand("%")) | |
34 | + let b:markdown_temp_file = getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
35 | + silent exe "write!" b:markdown_temp_file | |
36 | + silent exe "bwipeout!" b:markdown_temp_file | |
32 | 37 | call run#RunStart(#{ |
33 | 38 | \ cmd: b:markdown_command, |
34 | 39 | \ background: v:true, |
@@ -16,26 +16,30 @@ else | ||
16 | 16 | let b:rst_template_file = " --template=" .. b:rst_template_file |
17 | 17 | endif |
18 | 18 | |
19 | -let b:rst_command = "pandoc -f rst -t html5 --toc --toc-depth=3" | |
20 | - \ .. b:rst_css_file | |
21 | - \ .. b:rst_template_file | |
22 | - \ .." --metadata title=\""..expand("%:t:r").."\"" | |
23 | - \ .." -o "..getenv("TEMP")..g:slash..expand("%:t")..".html" | |
24 | - \ .." "..getenv("TEMP")..g:slash.."_"..expand("%:t") | |
25 | - | |
26 | 19 | function! s:OpenHTML() |
27 | 20 | exe "terminal ++close ++hidden cmd /C start" getenv("TEMP")..g:slash..expand("%:t")..".html" |
28 | 21 | endfunction |
29 | 22 | |
23 | +function! s:ComputeCommand(file) | |
24 | + return "pandoc -f rst -t html5 --toc --toc-depth=3" | |
25 | + \ .. b:rst_css_file | |
26 | + \ .. b:rst_template_file | |
27 | + \ .. " --metadata title=\"" .. expand("%:t:r") .. "\"" | |
28 | + \ .. " -o " .. getenv("TEMP") .. g:slash .. expand("%:t") .. ".html" | |
29 | + \ .. " " .. getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
30 | +endfunction | |
31 | + | |
30 | 32 | function! s:MakeHTML(...) |
31 | - if exists("b:rst_command") | |
32 | - silent exe "write!" getenv("TEMP")..g:slash.."_"..expand("%:t") | |
33 | - silent exe "bwipeout!" getenv("TEMP")..g:slash.."_"..expand("%:t") | |
33 | + if filereadable(expand("%")) | |
34 | + let b:rst_command = s:ComputeCommand(expand("%")) | |
35 | + let b:rst_temp_file = getenv("TEMP") .. g:slash .. "_" .. expand("%:t") | |
36 | + silent exe "write!" b:rst_temp_file | |
37 | + silent exe "bwipeout!" b:rst_temp_file | |
34 | 38 | call run#RunStart(#{ |
35 | 39 | \ cmd: b:rst_command, |
36 | 40 | \ background: v:true, |
37 | 41 | \ no_write: v:true |
38 | - }) | |
42 | + \ }) | |
39 | 43 | endif |
40 | 44 | endfunction |
41 | 45 |