--- /dev/null
+" Vim autoload file for the tohtml plugin.
+" Maintainer: Bram Moolenaar <Bram@vim.org>
+" Last Change: 2010 Jul 11
+"
+" Diff2HTML() added by Christian Brabandt <cb@256bit.org>
+
+func! tohtml#Convert2HTML(line1, line2)
+ if !&diff || exists("g:diff_one_file")
+ if a:line2 >= a:line1
+ let g:html_start_line = a:line1
+ let g:html_end_line = a:line2
+ else
+ let g:html_start_line = a:line2
+ let g:html_end_line = a:line1
+ endif
+ runtime syntax/2html.vim
+ else
+ let win_list = []
+ let buf_list = []
+ windo | if (&diff) | call add(win_list, winbufnr(0)) | endif
+ let save_hwf = exists("g:html_whole_filler")
+ let g:html_whole_filler = 1
+ for window in win_list
+ exe ":" . bufwinnr(window) . "wincmd w"
+ let g:html_start_line = 1
+ let g:html_end_line = line('$')
+ runtime syntax/2html.vim
+ call add(buf_list, bufnr('%'))
+ endfor
+ if !save_hwf
+ unlet g:html_whole_filler
+ endif
+ call tohtml#Diff2HTML(win_list, buf_list)
+ endif
+
+ unlet g:html_start_line
+ unlet g:html_end_line
+endfunc
+
+func! tohtml#Diff2HTML(win_list, buf_list)
+ let style = []
+ let html = []
+ call add(html, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"')
+ call add(html, ' "http://www.w3.org/TR/html4/loose.dtd">')
+ call add(html, '<html>')
+ call add(html, '<head>')
+ call add(html, '<title>diff</title>')
+ call add(html, '<meta name="Generator" content="Vim/7.3">')
+ "call add(html, '<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">')
+ call add(html, '</head>')
+ call add(html, '<body>')
+ call add(html, '<table border="1" width="100%">')
+ "call add(html, '<font face="monospace">')
+ call add(html, '<tr>')
+ for buf in a:win_list
+ call add(html, '<th>'.bufname(buf).'</th>')
+ endfor
+ call add(html, '</tr><tr>')
+
+ for buf in a:buf_list
+ let temp = []
+ exe bufwinnr(buf) . 'wincmd w'
+
+ " Grab the style information. Some of this will be duplicated...
+ 1
+ let style_start = search('^<style type="text/css">')
+ 1
+ let style_end = search('^</style>')
+ if style_start > 0 && style_end > 0
+ let style += getline(style_start + 1, style_end - 1)
+ endif
+
+ " Delete those parts that are not needed so
+ " we can include the rest into the resulting table
+ 1,/^<body/d_
+ $
+ ?</body>?,$d_
+ let temp = getline(1,'$')
+ " undo deletion of start and end part
+ " so we can later save the file as valid html
+ normal 2u
+ call add(html, '<td nowrap valign="top">')
+ let html += temp
+ call add(html, '</td>')
+
+ " Close this buffer
+ quit!
+ endfor
+
+ call add(html, '</tr>')
+ call add(html, '</table>')
+ call add(html, '</body>')
+ call add(html, '</html>')
+
+ let i = 1
+ let name = "Diff" . ".html"
+ while filereadable(name)
+ let name = substitute(name, '\d*\.html$', '', '') . i . ".html"
+ let i += 1
+ endw
+ exe "new " . name
+ set modifiable
+ call append(0, html)
+ if len(style) > 0
+ 1
+ let style_start = search('^</head>')
+ call append(style_start, '</style>')
+ call append(style_start, style)
+ call append(style_start, '<style type="text/css">')
+ endif
+endfunc
set cpo-=C
" Number lines when explicitely requested or when `number' is set
-if exists("html_number_lines")
+if exists("g:html_number_lines")
let s:numblines = html_number_lines
else
let s:numblines = &number
endif
" Font
-if exists("html_font")
+if exists("g:html_font")
let s:htmlfont = html_font . ", monospace"
else
let s:htmlfont = "monospace"
endif
" make copies of the user-defined settings that we may overrule
-if exists("html_dynamic_folds")
+if exists("g:html_dynamic_folds")
let s:html_dynamic_folds = 1
endif
-if exists("html_hover_unfold")
+if exists("g:html_hover_unfold")
let s:html_hover_unfold = 1
endif
-if exists("html_use_css")
+if exists("g:html_use_css")
let s:html_use_css = 1
endif
endif
" dynamic folding with no foldcolumn implies hover opens
-if exists("s:html_dynamic_folds") && exists("html_no_foldcolumn")
+if exists("s:html_dynamic_folds") && exists("g:html_no_foldcolumn")
let s:html_hover_unfold = 1
endif
" ignore folding overrides dynamic folding
-if exists("html_ignore_folding") && exists("s:html_dynamic_folds")
+if exists("g:html_ignore_folding") && exists("s:html_dynamic_folds")
unlet s:html_dynamic_folds
endif
endif
" Figure out proper MIME charset from the 'encoding' option.
-if exists("html_use_encoding")
+if exists("g:html_use_encoding")
let s:html_encoding = html_use_encoding
else
let s:vim_encoding = &encoding
let s:old_magic = &magic
set magic
-if exists("use_xhtml")
+if exists("g:use_xhtml")
if s:html_encoding != ""
exe "normal! a<?xml version=\"1.0\" encoding=\"" . s:html_encoding . "\"?>\n\e"
else
endif
" Cache html_no_pre in case we have to turn it on for non-css mode
-if exists("html_no_pre")
+if exists("g:html_no_pre")
let s:old_html_no_pre = html_no_pre
endif
let s:HtmlSpace = ' '
let s:LeadingSpace = ' '
let s:HtmlEndline = ''
-if exists("html_no_pre")
+if exists("g:html_no_pre")
let s:HtmlEndline = '<br' . s:tag_close
let s:LeadingSpace = ' '
let s:HtmlSpace = '\' . s:LeadingSpace
\ "</script>\n\e"
endif
-if exists("html_no_pre")
+if exists("g:html_no_pre")
exe "normal! a</head>\n<body>\n\e"
else
exe "normal! a</head>\n<body>\n<pre>\n\e"
" Now loop over all lines in the original text to convert to html.
" Use html_start_line and html_end_line if they are set.
-if exists("html_start_line")
+if exists("g:html_start_line")
let s:lnum = html_start_line
if s:lnum < 1 || s:lnum > line("$")
let s:lnum = 1
else
let s:lnum = 1
endif
-if exists("html_end_line")
+if exists("g:html_end_line")
let s:end = html_end_line
if s:end < s:lnum || s:end > line("$")
let s:end = line("$")
let s:margin = 0
endif
-if has('folding') && !exists('html_ignore_folding')
+if has('folding') && !exists('g:html_ignore_folding')
let s:foldfillchar = &fillchars[matchend(&fillchars, 'fold:')]
if s:foldfillchar == ''
let s:foldfillchar = '-'
while s:n > 0
let s:new = repeat(s:difffillchar, 3)
- if s:n > 2 && s:n < s:filler && !exists("html_whole_filler")
+ if s:n > 2 && s:n < s:filler && !exists("g:html_whole_filler")
let s:new = s:new . " " . s:filler . " inserted lines "
let s:n = 2
endif
- if !exists("html_no_pre")
+ if !exists("g:html_no_pre")
" HTML line wrapping is off--go ahead and fill to the margin
let s:new = s:new . repeat(s:difffillchar, &columns - strlen(s:new) - s:margin)
else
let s:new = ""
- if has('folding') && !exists('html_ignore_folding') && foldclosed(s:lnum) > -1 && !exists('s:html_dynamic_folds')
+ if has('folding') && !exists('g:html_ignore_folding') && foldclosed(s:lnum) > -1 && !exists('s:html_dynamic_folds')
"
" This is the beginning of a folded block (with no dynamic folding)
"
let s:new = s:numcol . foldtextresult(s:lnum)
- if !exists("html_no_pre")
+ if !exists("g:html_no_pre")
" HTML line wrapping is off--go ahead and fill to the margin
let s:new = s:new . repeat(s:foldfillchar, &columns - strlen(s:new))
endif
" Note that dynamic folds require using css so we just use css to take
" care of the leading spaces rather than using in the case of
" html_no_pre to make it easier
- if !exists("html_no_foldcolumn")
+ if !exists("g:html_no_foldcolumn")
" add fold column that can open the new fold
if s:allfolds[0].level > 1 && s:firstfold
let s:new = s:new . "<a class='toggle-open FoldColumn' href='javascript:toggleFold(\"fold".s:foldstack[0].id."\")'>"
" Note that dynamic folds require using css so we just use css to take
" care of the leading spaces rather than using in the case of
" html_no_pre to make it easier
- if !exists("html_no_foldcolumn")
+ if !exists("g:html_no_foldcolumn")
if empty(s:foldstack)
" add the empty foldcolumn for unfolded lines
let s:new = s:new . s:HtmlFormat(repeat(' ', s:foldcolumn), "FoldColumn")
" Speed loop (it's small - that's the trick)
" Go along till we find a change in hlID
while s:col <= s:len && s:id == diff_hlID(s:lnum, s:col) | let s:col = s:col + 1 | endwhile
- if s:len < &columns && !exists("html_no_pre")
+ if s:len < &columns && !exists("g:html_no_pre")
" Add spaces at the end to mark the changed line.
let s:line = s:line . repeat(' ', &columns - virtcol([s:lnum, s:len]) - s:margin)
let s:len = &columns
exe "normal! a</font>\e"
endif
-if exists("html_no_pre")
+if exists("g:html_no_pre")
exe "normal! a</body>\n</html>\e"
else
exe "normal! a</pre>\n</body>\n</html>\e"
" For Netscape 4, set <body> attributes too, though, strictly speaking, it's
" incorrect.
if exists("s:html_use_css")
- if exists("html_no_pre")
+ if exists("g:html_no_pre")
execute "normal! A\nbody { color: " . s:fgc . "; background-color: " . s:bgc . "; font-family: ". s:htmlfont ."; }\e"
else
execute "normal! A\npre { font-family: ". s:htmlfont ."; color: " . s:fgc . "; background-color: " . s:bgc . "; }\e"
%s+\(https\=://\S\{-}\)\(\([.,;:}]\=\(\s\|$\)\)\|[\\"'<>]\|>\|<\|"\)+<a href="\1">\1</a>\2+ge
" The DTD
-if exists("use_xhtml")
+if exists("g:use_xhtml")
exe "normal! gg$a\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\e"
else
exe "normal! gg0i<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n\e"
endif
-if exists("use_xhtml")
+if exists("g:use_xhtml")
exe "normal! gg/<html/e\na xmlns=\"http://www.w3.org/1999/xhtml\"\e"
endif
if exists("s:old_html_no_pre")
let html_no_pre = s:old_html_no_pre
unlet s:old_html_no_pre
-elseif exists("html_no_pre")
+elseif exists("g:html_no_pre")
unlet html_no_pre
endif