Hi,
the following patch adds diff functionality to the 2html.vim plugin.
This has been discussed at vim_use
http://groups.google.com/group/vim_use/browse_frm/thread/c29949f947701f2a
and since I hope this could be useful I am forwarding this patch to this
group.
The patch is available at
http://www.256bit.org/~chrisbra/patches/tohtml_diff4.diff (and also
attached to this mail.
Screenshot is available here:
http://www.256bit.org/~chrisbra/patches/Diff5.html
Hope this is of any use.
regards,
Christian
--
:wq!
--
You received this message from the "vim_dev" maillist.
For more information, visit http://www.vim.org/maillist.php
--- tohtml.vim.orig 2009-09-07 20:28:39.000000000 +0200
+++ tohtml.vim 2009-09-07 21:23:04.000000000 +0200
@@ -1,6 +1,26 @@
" Vim plugin for converting a syntax highlighted file to HTML.
" Maintainer: Bram Moolenaar <[email protected]>
-" Last Change: 2003 Apr 06
+" Last Change: 2009 September 07
+" Version: 4
+" Changelog: Version 4: Christian Brabandt <[email protected]>
+" - When in diff mode, created one html file for the
+" resulting diff.
+" - Added DTD Definition
+" - small html changes
+" Version 3: Christian Brabandt <[email protected]>
+" - Added td-attribute nospan, so that browsers
+" won't wrap long lines and all cells are synchronized
+" correctly
+" - Set g:html_start_line and g:html_end_line for each
+" file to first and last line, so a complete diff for all
+" files is created.
+" - Create a diffed html version using a table.
+" Version 2: Christian Brabandt <[email protected]>
+" - First Version, that creates a diffed html version
+" (using frames)
+" Version 1: Bram Moolenaar <[email protected]>
+" - original Version as distributed at www.vim.org
+"
" Don't do this when:
" - when 'compatible' is set
@@ -10,18 +30,91 @@
command -range=% TOhtml :call Convert2HTML(<line1>, <line2>)
func Convert2HTML(line1, line2)
- if a:line2 >= a:line1
- let g:html_start_line = a:line1
- let g:html_end_line = a:line2
+
+ if !&diff
+ 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 g:html_start_line = a:line2
- let g:html_end_line = a:line1
+ let winnr = []
+ windo | if (&diff) | call add(winnr, winbufnr(0)) | endif
+ for window in winnr
+ exe ":" . bufwinnr(window) . "wincmd w"
+ let g:html_start_line = 1
+ let g:html_end_line = line('$')
+ runtime syntax/2html.vim
+ endfor
+ call Diff2HTML(winnr)
endif
- runtime syntax/2html.vim
-
unlet g:html_start_line
unlet g:html_end_line
endfunc
+ func Diff2HTML(vars)
+ let bufnr = []
+ for wind in a:vars
+ let name=bufname(wind) . '.html'
+ if name == '.html'
+ let name='Untitled.html'
+ endif
+ call add(bufnr, bufnr(name))
+ endfor
+
+ 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.2">')
+ "call add(html, '<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">')
+ call add(html, '</head>')
+ call add(html, '<body bgcolor="#333333" text="#ffffff">')
+ call add(html, '<table border="1" width="100%">')
+ "call add(html, '<font face="monospace">')
+ call add(html, '<tr>')
+ for buf in a:vars
+ call add(html, '<th>'.bufname(buf).'</th>')
+ endfor
+ call add(html, '</tr><tr>')
+
+ for buf in bufnr
+ let temp=[]
+ exe ":" . bufwinnr(buf) . 'wincmd w'
+ " 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>')
+ 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)
+ endfunc
+
endif