]> git.r.bdr.sh - rbdr/dotfiles/blame_incremental - vim/ftplugin/textile.vim
Add ripgrep and hushlogin config
[rbdr/dotfiles] / vim / ftplugin / textile.vim
... / ...
CommitLineData
1" textile.vim
2"
3" Tim Harper (tim.theenchanter.com)
4
5command! -nargs=0 TextileRenderFile call TextileRenderBufferToFile()
6command! -nargs=0 TextileRenderTab call TextileRenderBufferToTab()
7command! -nargs=0 TextilePreview call TextileRenderBufferToPreview()
8noremap <buffer> <Leader>rp :TextilePreview<CR>
9noremap <buffer> <Leader>rf :TextileRenderFile<CR>
10noremap <buffer> <Leader>rt :TextileRenderTab<CR>
11setlocal ignorecase
12setlocal wrap
13setlocal lbr
14
15function! TextileRender(lines)
16 if (system('which ruby') == "")
17 throw "Could not find ruby!"
18 end
19
20 let text = join(a:lines, "\n")
21 let html = system("ruby -e \"def e(msg); puts msg; exit 1; end; begin; require 'rubygems'; rescue LoadError; e('rubygems not found'); end; begin; require 'redcloth'; rescue LoadError; e('RedCloth gem not installed. Run this from the terminal: sudo gem install RedCloth'); end; puts(RedCloth.new(\\$stdin.read).to_html(:textile))\"", text)
22 return html
23endfunction
24
25function! TextileRenderFile(lines, filename)
26 let html = TextileRender(getbufline(bufname("%"), 1, '$'))
27 let html = "<html><head><title>" . bufname("%") . "</title><body>\n" . html . "\n</body></html>"
28 return writefile(split(html, "\n"), a:filename)
29endfunction
30
31function! TextileRenderBufferToPreview()
32 let filename = "/tmp/textile-preview.html"
33 call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename)
34 " Verify if browser was set
35 if !exists("g:TextileBrowser")
36 let g:TextileBrowser='Safari'
37 endif
38 " call configured browser according OS
39 if !exists("g:TextileOS") || g:TextileOS == 'mac'
40 call system("open -a \"".g:TextileBrowser."\" ".filename)
41 else
42 echo g:TextileBrowser." ".filename
43 call system(g:TextileBrowser." ".filename)
44 endif
45endfunction
46
47function! TextileRenderBufferToFile()
48 let filename = input("Filename:", substitute(bufname("%"), "textile$", "html", ""), "file")
49 call TextileRenderFile(getbufline(bufname("%"), 1, '$'), filename)
50 echo "Rendered to '" . filename . "'"
51endfunction
52
53function! TextileRenderBufferToTab()
54 let html = TextileRender(getbufline(bufname("%"), 1, '$'))
55 tabnew
56 call append("^", split(html, "\n"))
57 set syntax=html
58endfunction
59