')
let diff_style_start = 0
let insert_index = 0
for buf in a:buf_list
let temp = []
exe bufwinnr(buf) . 'wincmd w'
" If text is folded because of user foldmethod settings, etc. we don't want
" to act on everything in a fold by mistake.
setlocal nofoldenable
" When not using CSS or when using xhtml, the line can be important.
" Assume it will be the same for all buffers and grab it from the first
" buffer. Similarly, need to grab the body end line as well.
if body_line == ''
1
call search('', 'b')
let s:body_end_line = getline('.')
endif
" Grab the style information. Some of this will be duplicated so only insert
" it if it's not already there. {{{
1
let style_start = search('^')
if style_start > 0 && style_end > 0
let buf_styles = getline(style_start + 1, style_end - 1)
for a_style in buf_styles
if index(style, a_style) == -1
if diff_style_start == 0
if a_style =~ '\\_s\+.*id='oneCharWidth'.*\_s\+.*id='oneInputWidth'.*\_s\+.*id='oneEmWidth'\)\?\zs/d_
$
??,$d_
let temp = getline(1,'$')
" clean out id on the main content container because we already set it on
" the table
let temp[0] = substitute(temp[0], " id='vimCodeElement[^']*'", "", "")
" undo deletion of start and end part
" so we can later save the file as valid html
" TODO: restore using grabbed lines if undolevel is 1?
normal! 2u
if s:settings.use_css
call add(html, '
')
elseif s:settings.use_xhtml
call add(html, '
')
else
call add(html, '
')
endif
let html += temp
call add(html, '
')
" Close this buffer
" TODO: the comment above says we're going to allow saving the file
" later...but here we discard it?
quit!
endfor
let html[body_line_num] = body_line
call add(html, '
')
call add(html, '
')
call add(html, s:body_end_line)
call add(html, '')
" The generated HTML is admittedly ugly and takes a LONG time to fold.
" Make sure the user doesn't do syntax folding when loading a generated file,
" using a modeline.
call add(html, '')
let i = 1
let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html")
" Find an unused file name if current file name is already in use
while filereadable(name)
let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e")
let i += 1
endwhile
exe "topleft new " . name
setlocal modifiable
" just in case some user autocmd creates content in the new buffer, make sure
" it is empty before proceeding
%d
" set the fileencoding to match the charset we'll be using
let &l:fileencoding=s:settings.vim_encoding
" According to http://www.w3.org/TR/html4/charset.html#doc-char-set, the byte
" order mark is highly recommend on the web when using multibyte encodings. But,
" it is not a good idea to include it on UTF-8 files. Otherwise, let Vim
" determine when it is actually inserted.
if s:settings.vim_encoding == 'utf-8'
setlocal nobomb
else
setlocal bomb
endif
call append(0, html)
if len(style) > 0
1
let style_start = search('^')-1
" add required javascript in reverse order so we can just call append again
" and again without adjusting {{{
let s:uses_script = s:settings.dynamic_folds || s:settings.line_ids || !empty(s:settings.prevent_copy)
" insert script closing tag if needed
if s:uses_script
call append(style_start, [
\ '',
\ s:settings.use_xhtml ? '//]]>' : '-->',
\ ""
\ ])
endif
" insert script which corrects the size of small input elements in
" prevent_copy mode. See 2html.vim for details on why this is needed and how
" it works.
if !empty(s:settings.prevent_copy)
call append(style_start, [
\ '',
\ '/* simulate a "ch" unit by asking the browser how big a zero character is */',
\ 'function FixCharWidth() {',
\ ' /* get the hidden element which gives the width of a single character */',
\ ' var goodWidth = document.getElementById("oneCharWidth").clientWidth;',
\ ' /* get all input elements, we''ll filter on class later */',
\ ' var inputTags = document.getElementsByTagName("input");',
\ ' var ratio = 5;',
\ ' var inputWidth = document.getElementById("oneInputWidth").clientWidth;',
\ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;',
\ ' if (inputWidth > goodWidth) {',
\ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {',
\ ' ratio += 5;',
\ ' }',
\ ' document.getElementById("vimCodeElement'.s:settings.id_suffix.'").className = "em"+ratio;',
\ ' }',
\ '}'
\ ])
endif
" insert javascript to get IDs from line numbers, and to open a fold before
" jumping to any lines contained therein
if s:settings.line_ids
call append(style_start, [
\ " /* Always jump to new location even if the line was hidden inside a fold, or",
\ " * we corrected the raw number to a line ID.",
\ " */",
\ " if (lineElem) {",
\ " lineElem.scrollIntoView(true);",
\ " }",
\ " return true;",
\ "}",
\ "if ('onhashchange' in window) {",
\ " window.onhashchange = JumpToLine;",
\ "}"
\ ])
if s:settings.dynamic_folds
call append(style_start, [
\ "",
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
\ " var node = lineElem;",
\ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
\ " {",
\ " if (node.className == 'closed-fold')",
\ " {",
\ " /* toggle open the fold ID (remove window ID) */",
\ " toggleFold(node.id.substr(4));",
\ " }",
\ " node = node.parentNode;",
\ " }",
\ ])
endif
endif
if s:settings.line_ids
call append(style_start, [
\ "",
\ "/* function to open any folds containing a jumped-to line before jumping to it */",
\ "function JumpToLine()",
\ "{",
\ " var lineNum;",
\ " lineNum = window.location.hash;",
\ " lineNum = lineNum.substr(1); /* strip off '#' */",
\ "",
\ " if (lineNum.indexOf('L') == -1) {",
\ " lineNum = 'L'+lineNum;",
\ " }",
\ " if (lineNum.indexOf('W') == -1) {",
\ " lineNum = 'W1'+lineNum;",
\ " }",
\ " var lineElem = document.getElementById(lineNum);"
\ ])
endif
" Insert javascript to toggle matching folds open and closed in all windows,
" if dynamic folding is active.
if s:settings.dynamic_folds
call append(style_start, [
\ " function toggleFold(objID)",
\ " {",
\ " for (win_num = 1; win_num <= ".len(a:buf_list)."; win_num++)",
\ " {",
\ " var fold;",
\ ' fold = document.getElementById("win"+win_num+objID);',
\ " if(fold.className == 'closed-fold')",
\ " {",
\ " fold.className = 'open-fold';",
\ " }",
\ " else if (fold.className == 'open-fold')",
\ " {",
\ " fold.className = 'closed-fold';",
\ " }",
\ " }",
\ " }",
\ ])
endif
if s:uses_script
" insert script tag; javascript is always needed for the line number
" normalization for URL hashes
call append(style_start, [
\ "