From 1f913965ccd1277105fdc4498dc74fa49addfd47 Mon Sep 17 00:00:00 2001 From: JamshedVesuna Date: Fri, 24 Apr 2015 13:01:27 -0700 Subject: [PATCH] Supports image loading and local html rendering --- plugin/vim-markdown-preview.vim | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/plugin/vim-markdown-preview.vim b/plugin/vim-markdown-preview.vim index 71164ad..8b91b67 100644 --- a/plugin/vim-markdown-preview.vim +++ b/plugin/vim-markdown-preview.vim @@ -48,5 +48,60 @@ function! Vim_Markdown_Preview() endif endfunction + +"Renders html locally and displays images +function! Vim_Markdown_Preview_Local() + + let BROWSER = 'google-chrome' + let OSNAME = 'Unidentified' + let REMOVE_TEMP_FILE = 0 "To remove the temp file, set to 1 + + if has('win32') + " Not yet used + let OSNAME = 'win32' + endif + if has('unix') + let OSNAME = 'unix' + endif + if has('mac') + let OSNAME = 'mac' + let BROWSER = 'safari' + endif + + let curr_file = expand('%:p') + call system('markdown ' . curr_file . ' > ' . curr_file . '.html') + + if OSNAME == 'unix' && BROWSER == 'google-chrome' + let chrome_wid = system("xdotool search --name '". curr_file . ".html - Google Chrome'") + if !chrome_wid + "sleep 300m + call system('see ' . curr_file . '.html & > /dev/null &') + else + let curr_wid = system('xdotool getwindowfocus') + call system('xdotool windowmap ' . chrome_wid) + call system('xdotool windowactivate ' . chrome_wid) + call system("xdotool key 'ctrl+r'") + call system('xdotool windowactivate ' . curr_wid) + endif + "sleep 700m + endif + + if OSNAME == 'mac' && BROWSER == 'safari' + call system('open -g ' . curr_file . '.html') + endif + + if REMOVE_TEMP_FILE + call system('rm ' . curr_file . '.html') + endif +endfunction + + +"Maps Ctrl-p to Vim_Markdown_Preview() autocmd Filetype markdown,md map :call Vim_Markdown_Preview() + +"Maps Ctrl-p to Vim_Markdown_Preview_Local() - saves the html file locally and +"displays images in path +"autocmd Filetype markdown,md map :call Vim_Markdown_Preview_Local() + +"Automatically call Vim_Markdown_Preview() on buffer write "autocmd BufWritePost *.markdown,*.md :call Vim_Markdown_Preview() -- 2.45.2