Open orschiro opened 12 years ago
@orschiro Dou have multimarkdown
binary installed and added to the PATH
environment variable i.e. available as a command?
@swaroopch Yes I have, i.e. I can run :!markdown.exe
in Gvim.
By the way, you should state in your Readme that multimarkdown is actually needed for your plugin.
Regards
@orschiro You can edit line at https://github.com/swaroopch/vim-markdown-preview/blob/master/ftplugin/markdown.vim#L26 - change "multimarkdown" to "markdown" and try it.
I have updated the README noting the dependency.
Still the same error but this time reasonable since I do not have markdown installed.
However, multimarkdown.exe is definitely on the PATH and runs properly. Probably it's a problem related to the tmp path on Windows?
I changed this section to
let output_text_filename = "C:\Windows\Temp\markdown-preview.md"
let output_html_filename = "C:\Windows\Temp\markdown-preview.html"
Now I do not get any error message in Gvim anymore. However, also no preview window is shown. Hence, you may have to revise the open_file function?
@orschiro Use the following and see whether it has any effect:
function! s:open_file(filename)
if has('mac') || has('macunix')
call system("open " . fnameescape(a:filename))
elseif has('unix')
call system("gnome-open " . fnameescape(a:filename))
else
call system("start " . fnameescape(a:filename))
endif
endfunction
We're getting closer. He tries to open a temp file C:/Users/Robert/AppData/Local/Temp/VIoB2F7.tmp
that does not exist.
So obviously the problem lies here now with the temporary file:
let output_text_filename = "C:\WINDOWS\Temp\markdown-preview.md"
let output_html_filename = "C:\WINDOWS\Temp\markdown-preview.html"
The same result when I use your default setting:
let output_text_filename = "/tmp/markdown-preview.md"
let output_html_filename = "/tmp/markdown-preview.html"
@orschiro Can you use :echo
to print the result of fnameescape(a:filename)
and then run start <filename>
in the DOS prompt and see what happens?
What do you mean exactly?
When I run :echo
in Gvim while I have a md file open nothing happens. Also :echo fnameescape(a:filename)
or :echo fnameescape(a:README.md)
do not work. They show me that the expression is not valid.
Regards
@orschiro You'll have to do the echo
within the function.
I have not tested it on Linux or Mac yet but I got it to work on Windows 7. I had to move much of the code around, and unfortunately I needed to use PoSh. @Swaroopch, when your script tries to write-out the preview files in a "tmp" folder in the working directory, it fails unless the "tmp" folder already exists. Because of this, I configured the script to write to a specific folder ($vimruntime . temp) each time on windows, but at this time the folder needs to be created manually before you use it. Oddly in CMD, the "start" command ignore anything within quotes so
start www.github.com
works but
start "www.github.com"
will start a new CMD in the current working directory. This makes it hard because vim is installed in "Program Files (x86)" on my system. Fortunately PoSh doesn't have this problem so I just call that and have it execute "start" instead. That means my version of your script may not work on older versions of windows unless PoSh is installed.
" Language: Markdown
" Maintainer: Swaroop C H <swaroop@swaroopch.com>
" URL: https://github.com/swaroopch/vim-markdown-preview
" License: WTFPL
" Dependencies: http://fletcherpenney.net/multimarkdown/
if exists("b:loaded_markdown_preview")
finish
endif
let b:loaded_markdown_preview = 1
function! s:ShowMarkdownPreview(line1, line2)
let text = getline(a:line1, a:line2)
let ofilename = "markdown-preview.md"
let nfilename = "markdown-preview.html"
if has('mac') || has('macunix')
call writefile(text, "/tmp/" . ofilename)
call system("multimarkdown /tmp/" . ofilename . " > /tmp/" . nfilename)
call system("open /tmp/" . nfilename)
elseif has('unix')
call writefile(text, "/tmp/" . ofilename)
call system("multimarkdown /tmp/" . ofilename . " > /tmp/" . nfilename)
call system("gnome-open /tmp/" . nfilename)
elseif has('win32') || has('win64') || has('win16')
call writefile(text, $vimruntime . '\tmp\' . ofilename)
call system('multimarkdown "' . $vimruntime . '\tmp\' . ofilename . '" -o "' . $vimruntime . '\tmp\' . nfilename . '"')
call system("powershell start '" . $vimruntime . '\tmp\' . nfilename . "'")
endif
endfunction
command! -range=% MarkdownPreview call s:ShowMarkdownPreview(<line1>, <line2>)
UPDATE: Just to let anyone reading this know, my newer version that has already been pulled upstream for months now is very different than this version, like the dependency on PoSh has been removed (now compatible to older versions of windows) and the temp file is now saved under %AppData% of the current user (more secure).
@CyberOPS This looks great, can you please send a pull request?
I made more updates to the script and sent a pull request. I assume your using a Mac, so I hope my changes didn't screw anything up.
Hello,
When running
:MarkdownPreview
on my Windows system I get the error that"function <SNR>59_ShowMarkdownPreview":
cannot be executed. Do I miss something else in order to generate the preview?Regards