Created
May 8, 2009 19:00
-
-
Save jashmenn/108933 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Vim Markdown preview | |
" | |
" * compile vim with ruby support | |
" * sudo gem install rdiscount (update load path to absolute path below) | |
" * add this file to | |
" ~/.vim/ftplugin/mkd.vim | |
function! PreviewMKD() | |
ruby << EOF | |
require 'rubygems' | |
$:.unshift("/usr/local/lib/ruby/gems/1.8/gems/rdiscount-1.3.4/lib") | |
require 'rdiscount' | |
t = "" | |
VIM::Buffer.current.count.times {|i| t += "#{VIM::Buffer.current[i + 1]}\n"} | |
html_file = VIM::Buffer.current.name.gsub(/.(md|mkd|markdown)$/, '.html') | |
if html_file == VIM::Buffer.current.name | |
print "Error! - This file extension is not supported for Markdown previews" | |
end | |
File.open(html_file, 'w') do |f| | |
f.write(RDiscount.new(t).to_html) | |
end | |
system("open #{html_file}") | |
EOF | |
endfunction | |
map <Leader>p :call PreviewMKD()<CR> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment