")
@@ -503,6 +503,11 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
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
@@ -539,14 +544,12 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
" add required javascript in reverse order so we can just call append again
" and again without adjusting {{{
- " insert script closing tag if any javascript is needed
- if s:settings.dynamic_folds || !empty(s:settings.prevent_copy)
- call append(style_start, [
- \ '',
- \ s:settings.use_xhtml ? '//]]>' : '-->',
- \ ""
- \ ])
- endif
+ " insert script closing tag
+ call append(style_start, [
+ \ '',
+ \ s:settings.use_xhtml ? '//]]>' : '-->',
+ \ ""
+ \ ])
" 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
@@ -572,6 +575,55 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
\ '}'
\ ])
endif
+ "
+ " insert javascript to get IDs from line numbers, and to open a fold before
+ " jumping to any lines contained therein
+ 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')",
+ \ " {",
+ \ " if (node.className == 'closed-fold')",
+ \ " {",
+ \ " /* toggle open the fold ID (remove window ID) */",
+ \ " toggleFold(node.id.substr(4));",
+ \ " }",
+ \ " node = node.parentNode;",
+ \ " }",
+ \ ])
+ endif
+ 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;",
+ \ " }",
+ \ " lineElem = document.getElementById(lineNum);"
+ \ ])
" Insert javascript to toggle matching folds open and closed in all windows,
" if dynamic folding is active.
@@ -596,12 +648,11 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
\ ])
endif
- " insert script tag if any javascript is needed
- if s:settings.dynamic_folds || s:settings.prevent_copy != ""
- call append(style_start, [
- \ ""
- \ ])
-endif
+" insert script closing tag
+call extend(s:lines, [
+ \ '',
+ \ s:settings.use_xhtml ? '//]]>' : '-->',
+ \ ""
+ \ ])
call extend(s:lines, [""])
if !empty(s:settings.prevent_copy)
call extend(s:lines,
- \ ["",
+ \ ["",
\ "",
\ "
0
",
\ "
",
\ ""
\ ])
else
- call extend(s:lines, [""])
+ call extend(s:lines, [""])
endif
if s:settings.no_pre
" if we're not using CSS we use a font tag which can't have a div inside
@@ -1242,7 +1301,7 @@ while s:lnum <= s:end
if s:settings.number_lines
" Indent if line numbering is on. Indent gets style of line number
" column.
- let s:new = s:HtmlFormat_n(repeat(' ', s:margin), s:LINENR_ID, 0) . s:new
+ let s:new = s:HtmlFormat_n(repeat(' ', s:margin), s:LINENR_ID, 0, 0) . s:new
endif
if s:settings.dynamic_folds && !s:settings.no_foldcolumn && s:foldcolumn > 0
" Indent for foldcolumn if there is one. Assume it's empty, there should
@@ -1274,7 +1333,7 @@ while s:lnum <= s:end
endif
" put numcol in a separate group for sake of unselectable text
- let s:new = (s:settings.number_lines ? s:HtmlFormat_n(s:numcol, s:FOLDED_ID, 0): "") . s:HtmlFormat_t(s:new, s:FOLDED_ID, 0)
+ let s:new = (s:settings.number_lines ? s:HtmlFormat_n(s:numcol, s:FOLDED_ID, 0, s:lnum): "") . s:HtmlFormat_t(s:new, s:FOLDED_ID, 0)
" Skip to the end of the fold
let s:new_lnum = foldclosedend(s:lnum)
@@ -1355,7 +1414,7 @@ while s:lnum <= s:end
" Add fold text, moving the span ending to the next line so collapsing
" of folds works correctly.
" Put numcol in a separate group for sake of unselectable text.
- let s:new = s:new . (s:settings.number_lines ? s:HtmlFormat_n(s:numcol, s:FOLDED_ID, 0) : "") . substitute(s:HtmlFormat_t(foldtextresult(s:lnum), s:FOLDED_ID, 0), '', s:HtmlEndline.'\n\0', '')
+ let s:new = s:new . (s:settings.number_lines ? s:HtmlFormat_n(s:numcol, s:FOLDED_ID, 0, 0) : "") . substitute(s:HtmlFormat_t(foldtextresult(s:lnum), s:FOLDED_ID, 0), '', s:HtmlEndline.'\n\0', '')
let s:new = s:new . ""
" open the fold now that we have the fold text to allow retrieval of
@@ -1389,7 +1448,9 @@ while s:lnum <= s:end
" Now continue with the unfolded line text
if s:settings.number_lines
- let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0)
+ let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0, s:lnum)
+ else
+ let s:new = s:new . s:HtmlFormat_n("", s:LINENR_ID, 0, s:lnum)
endif
" Get the diff attribute, if any.
@@ -1479,7 +1540,7 @@ while s:lnum <= s:end
" Output the text with the same synID, with class set to the highlight ID
" name, unless it has been concealed completely.
if strlen(s:expandedtab) > 0
- let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id, s:diff_id, 0)
+ let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id, s:diff_id, "", 0)
endif
endwhile
endif
@@ -1531,6 +1592,11 @@ unlet s:lines
" stripped from the final output.
%s!\v(%(^|\s+)%(vim?|ex)):!\1\:!ge
+" 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 append(line('$'), "")
+
" Now, when we finally know which, we define the colors and styles
if s:settings.use_css
1;/