*** syntax\2html.vim	Mon Feb 09 21:58:08 2009
--- \Documents and Settings\Ben\vimfiles\syntax\2html.vim	Mon Feb 09 22:43:13 2009
***************
*** 1,13 ****
  " Vim syntax support file
  " Maintainer: Bram Moolenaar <Bram@vim.org>
! " Last Change: 2009 Jan 28
! "	       (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>)
! "	       (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>)
! "	       (made w3 compliant by Edd Barrett <vext01@gmail.com>)
! "	       (added html_font. Edd Barrett <vext01@gmail.com>)
  
  " Transform a file into HTML, using the current syntax highlighting.
  
  " Number lines when explicitely requested or when `number' is set
  if exists("html_number_lines")
    let s:numblines = html_number_lines
--- 1,18 ----
  " Vim syntax support file
  " Maintainer: Bram Moolenaar <Bram@vim.org>
! " Last Change: 2009 Feb 09
! "              (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>)
! "              (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>)
! "              (made w3 compliant by Edd Barrett <vext01@gmail.com>)
! "              (added html_font. Edd Barrett <vext01@gmail.com>)
! "              (dynamic folding by Ben Fritz <fritzophrenic@gmail.com>)
  
  " Transform a file into HTML, using the current syntax highlighting.
  
+ " this file uses line continuations
+ let s:cpo_sav = &cpo
+ set cpo-=C
+ 
  " Number lines when explicitely requested or when `number' is set
  if exists("html_number_lines")
    let s:numblines = html_number_lines
***************
*** 22,27 ****
--- 27,63 ----
    let s:htmlfont = "monospace"
  endif
  
+ " use copies of all the user-defined settings that might overwrite each other
+ if exists("html_dynamic_folds")
+   let s:html_dynamic_folds = 1
+ endif
+ if exists("html_hover_unfold")
+   let s:html_hover_unfold = 1
+ endif
+ if exists("html_use_css")
+   let s:html_use_css = 1
+ endif
+ 
+ " hover opening implies dynamic folding
+ if exists("s:html_hover_unfold")
+   let s:html_dynamic_folds = 1
+ endif
+ 
+ " dynamic folding with no foldcolumn implies hover opens
+ if exists("s:html_dynamic_folds") && exists("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")
+   unlet s:html_dynamic_folds
+ endif
+ 
+ " dynamic folding implies css
+ if exists("s:html_dynamic_folds")
+   let s:html_use_css = 1
+ endif
+ 
  " When not in gui we can only guess the colors.
  if has("gui_running")
    let s:whatterm = "gui"
***************
*** 62,68 ****
    endfun
  endif
  
! if !exists("html_use_css")
    " Return opening HTML tag for given highlight id
    function! s:HtmlOpening(id)
      let a = ""
--- 98,104 ----
    endfun
  endif
  
! if !exists("s:html_use_css")
    " Return opening HTML tag for given highlight id
    function! s:HtmlOpening(id)
      let a = ""
***************
*** 150,155 ****
--- 186,211 ----
    return a
  endfun
  
+ if exists("s:html_dynamic_folds")
+ 
+   " compares two folds as stored in our list of folds
+   " A fold is "less" than another if it starts at an earlier line number,
+   " or ends at a later line number, ties broken by fold level
+   function! s:FoldCompare(f1, f2)
+     if a:f1.firstline != a:f2.firstline
+       " put it before if it starts earlier
+       return a:f1.firstline - a:f2.firstline
+     elseif a:f1.lastline != a:f2.lastline
+       " put it before if it ends later
+       return a:f2.lastline - a:f1.lastline
+     else
+       " if folds begin and end on the same lines, put lowest fold level first
+       return a:f1.level - a:f2.level
+     endif
+   endfunction
+ 
+ endif
+ 
  " Figure out proper MIME charset from the 'encoding' option.
  if exists("html_use_encoding")
    let s:html_encoding = html_use_encoding
***************
*** 183,189 ****
    endif
  endif
  
- 
  " Set some options to make it work faster.
  " Don't report changes for :substitute, there will be many of them.
  let s:old_title = &title
--- 239,244 ----
***************
*** 228,234 ****
    let s:old_html_no_pre = html_no_pre
  endif
  
! if !exists("html_use_css")
    " Can't put font tags in <pre>
    let html_no_pre=1
  endif
--- 283,289 ----
    let s:old_html_no_pre = html_no_pre
  endif
  
! if !exists("s:html_use_css")
    " Can't put font tags in <pre>
    let html_no_pre=1
  endif
***************
*** 251,259 ****
    exe "normal! a<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:html_encoding . '"' . s:tag_close . "\n\e"
  endif
  
! if exists("html_use_css")
!   exe "normal! a<style type=\"text/css\">\n<!--\n-->\n</style>\n\e"
  endif
  if exists("html_no_pre")
    exe "normal! a</head>\n<body>\n\e"
  else
--- 306,389 ----
    exe "normal! a<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:html_encoding . '"' . s:tag_close . "\n\e"
  endif
  
! if exists("s:html_use_css")
!   if exists("s:html_dynamic_folds")
!     if exists("s:html_hover_unfold")
!       " if we are doing hover_unfold, use css 2 with css 1 fallback for IE6
!       exe "normal! a".
!           \ "<style type=\"text/css\">\n<!--\n".
!           \ ".FoldColumn { text-decoration: none; white-space: pre; }\n\n".
!           \ "body * { margin: 0; padding: 0; }\n".
!           \ "\n".
!           \ ".open-fold   > .Folded { display: none;  }\n".
!           \ ".open-fold   > .fulltext { display: inline; }\n".
!           \ ".closed-fold > .fulltext { display: none;  }\n".
!           \ ".closed-fold > .Folded { display: inline; }\n".
!           \ "\n".
!           \ ".open-fold   > .toggle-open   { display: none;   }\n".
!           \ ".open-fold   > .toggle-closed { display: inline; }\n".
!           \ ".closed-fold > .toggle-open   { display: inline; }\n".
!           \ ".closed-fold > .toggle-closed { display: none;   }\n"
!       exe "normal! a\n/* opening a fold while hovering won't be supported by IE6 and other\n".
!           \ "similar browsers, but it should fail gracefully. */\n".
!           \ ".closed-fold:hover > .fulltext { display: inline; }\n".
!           \ ".closed-fold:hover > .Folded { display: none; }\n"
!       exe "normal! a-->\n</style>\n"
!       exe "normal! a<!--[if lt IE 7]>".
!             \ "<style type=\"text/css\">\n".
!             \ ".open-fold   .Folded      { display: none; }\n".
!             \ ".open-fold   .fulltext      { display: inline; }\n".
!             \ ".open-fold   .toggle-open   { display: none; }\n".
!             \ ".closed-fold .toggle-closed { display: inline; }\n".
!             \ "\n".
!             \ ".closed-fold .fulltext      { display: none; }\n".
!             \ ".closed-fold .Folded      { display: inline; }\n".
!             \ ".closed-fold .toggle-open   { display: inline; }\n".
!             \ ".closed-fold .toggle-closed { display: none; }\n".
!             \ "</style>\n".
!             \ "<![endif]-->\n"
!     else
!       " if we aren't doing hover_unfold, use CSS 1 only
!       exe "normal! a<style type=\"text/css\">\n<!--\n".
!             \ ".FoldColumn { text-decoration: none; white-space: pre; }\n\n".
!             \ ".open-fold   .Folded      { display: none; }\n".
!             \ ".open-fold   .fulltext      { display: inline; }\n".
!             \ ".open-fold   .toggle-open   { display: none; }\n".
!             \ ".closed-fold .toggle-closed { display: inline; }\n".
!             \ "\n".
!             \ ".closed-fold .fulltext      { display: none; }\n".
!             \ ".closed-fold .Folded      { display: inline; }\n".
!             \ ".closed-fold .toggle-open   { display: inline; }\n".
!             \ ".closed-fold .toggle-closed { display: none; }\n".
!             \ "-->\n</style>\n"
!     endif
!   else
!     " if we aren't doing any dynamic folding, no need for any special rules
!     exe "normal! a<style type=\"text/css\">\n<!--\n-->\n</style>\n\e"
!   endif
  endif
+ 
+ if exists("s:html_dynamic_folds")
+   exe "normal! a\n".
+         \ "<script type='text/javascript'>\n".
+         \ "<!--\n".
+         \ "function toggleFold(objID)\n".
+         \ "{\n".
+         \ "  var fold;\n".
+         \ "  fold = document.getElementById(objID);\n".
+         \ "  if(fold.className == 'closed-fold')\n".
+         \ "  {\n".
+         \ "    fold.className = 'open-fold';\n".
+         \ "  }\n".
+         \ "  else if (fold.className == 'open-fold')\n".
+         \ "  {\n".
+         \ "    fold.className = 'closed-fold';\n".
+         \ "  }\n".
+         \ "}\n".
+         \ "-->\n".
+         \ "</script>\n\e"
+ endif
+ 
  if exists("html_no_pre")
    exe "normal! a</head>\n<body>\n\e"
  else
***************
*** 265,271 ****
  " List of all id's
  let s:idlist = ","
  
! " Loop over all lines in the original text.
  " Use html_start_line and html_end_line if they are set.
  if exists("html_start_line")
    let s:lnum = html_start_line
--- 395,474 ----
  " List of all id's
  let s:idlist = ","
  
! " First do some preprocessing for dynamic folding. Do this for the entire file
! " so we don't accidentally start within a closed fold or something.
! let s:allfolds = []
! 
! if exists("s:html_dynamic_folds")
!   let s:lnum = 1
!   let s:end = line('$')
!   " save the fold text and set it to standard so we can determine fold levels
!   let s:foldtext_save = &foldtext
!   set foldtext&
! 
!   " we will set the foldcolumn in the html to the greater of the maximum fold
!   " level and the current foldcolumn setting
!   let s:foldcolumn = &foldcolumn
! 
!   " get the fold text and line numbers for all closed folds (except for
!   " duplicates, of which only one will be added)
!   while s:lnum < s:end
!     if foldclosed(s:lnum) == s:lnum
!       " default fold text has '+-' and then a number of dashes equal to fold
!       " level, so subtract 2 from index of first non-dash after the dashes
!       " in order to get the fold level of the current fold
!       let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
!       if s:level+1 > s:foldcolumn
!         let s:foldcolumn = s:level+1
!       endif
!       let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
!       " only add the fold if it isn't a duplicate (which would be the last
!       " one added)
!       call add(s:allfolds, s:newfold)
!       execute s:lnum."foldopen"
!     else
!       let s:lnum = s:lnum + 1
!     endif
!   endwhile
! 
!   " close all folds to get info for originally open folds
!   silent! %foldclose!
!   let s:lnum = 1
! 
!   " the originally open folds will be all lines folded currently that aren't
!   " already in the list (except for two folds that start and end on the same
!   " line, but there is no real reason to duplicate that in the html)
!   while s:lnum < s:end
!     if foldclosed(s:lnum) == s:lnum
!       " default fold text has '+-' and then a number of dashes equal to fold
!       " level, so subtract 2 from index of first non-dash after the dashes
!       " in order to get the fold level of the current fold
!       let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
!       if s:level+1 > s:foldcolumn
!         let s:foldcolumn = s:level+1
!       endif
!       let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
!       " only add the fold if we don't already have it
!       if empty(s:allfolds) || index(s:allfolds, s:newfold) == -1
!         let s:newfold.type = "open-fold"
!         call add(s:allfolds, s:newfold)
!       endif
!       execute s:lnum."foldopen"
!     else
!       let s:lnum = s:lnum + 1
!     endif
!   endwhile
! 
!   call sort(s:allfolds, "s:FoldCompare")
! 
!   let &foldtext = s:foldtext_save
!   unlet s:foldtext_save
! 
!   " close all folds again so we can get the fold text as we go
!   silent! %foldclose! 
! endif
! 
! " 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")
    let s:lnum = html_start_line
***************
*** 283,288 ****
--- 486,495 ----
  else
    let s:end = line("$")
  endif
+ 
+ " stack to keep track of all the folds the current line is in
+ let s:foldstack = []
+ 
  if s:numblines
    let s:margin = strlen(s:end) + 1
  else
***************
*** 300,305 ****
--- 507,513 ----
    let s:difffillchar = '-'
  endif
  
+ let s:foldId = 0
  
  while s:lnum <= s:end
  
***************
*** 311,331 ****
        let s:new = repeat(s:difffillchar, 3)
  
        if s:n > 2 && s:n < s:filler && !exists("html_whole_filler")
! 	let s:new = s:new . " " . s:filler . " inserted lines "
! 	let s:n = 2
        endif
  
        if !exists("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 = s:new . repeat(s:difffillchar, 3)
        endif
  
        let s:new = s:HtmlFormat(s:new, "DiffDelete")
        if s:numblines
! 	" Indent if line numbering is on; must be after escaping.
! 	let s:new = repeat(s:LeadingSpace, s:margin) . s:new
        endif
        exe s:newwin . "wincmd w"
        exe "normal! a" . s:new . s:HtmlEndline . "\n\e"
--- 519,539 ----
        let s:new = repeat(s:difffillchar, 3)
  
        if s:n > 2 && s:n < s:filler && !exists("html_whole_filler")
!         let s:new = s:new . " " . s:filler . " inserted lines "
!         let s:n = 2
        endif
  
        if !exists("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 = s:new . repeat(s:difffillchar, 3)
        endif
  
        let s:new = s:HtmlFormat(s:new, "DiffDelete")
        if s:numblines
!         " Indent if line numbering is on; must be after escaping.
!         let s:new = repeat(s:LeadingSpace, s:margin) . s:new
        endif
        exe s:newwin . "wincmd w"
        exe "normal! a" . s:new . s:HtmlEndline . "\n\e"
***************
*** 339,354 ****
  
    " Start the line with the line number.
    if s:numblines
!     let s:new = repeat(' ', s:margin - 1 - strlen(s:lnum)) . s:lnum . ' '
    else
!     let s:new = ""
    endif
  
!   if has('folding') && !exists('html_ignore_folding') && foldclosed(s:lnum) > -1
      "
!     " This is the beginning of a folded block
      "
!     let s:new = s:new . foldtextresult(s:lnum)
      if !exists("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))
--- 547,564 ----
  
    " Start the line with the line number.
    if s:numblines
!     let s:numcol = repeat(' ', s:margin - 1 - strlen(s:lnum)) . s:lnum . ' '
    else
!     let s:numcol = ""
    endif
  
!   let s:new = ""
! 
!   if has('folding') && !exists('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")
        " HTML line wrapping is off--go ahead and fill to the margin
        let s:new = s:new . repeat(s:foldfillchar, &columns - strlen(s:new))
***************
*** 361,373 ****
  
    else
      "
!     " A line that is not folded.
      "
      let s:line = getline(s:lnum)
      let s:len = strlen(s:line)
  
      if s:numblines
!       let s:new = s:HtmlFormat(s:new, "lnr")
      endif
  
      " Get the diff attribute, if any.
--- 571,648 ----
  
    else
      "
!     " A line that is not folded, or doing dynamic folding.
      "
      let s:line = getline(s:lnum)
+ 
      let s:len = strlen(s:line)
  
+     if exists("s:html_dynamic_folds")
+       " First close off any open folds that end on this line
+       while !empty(s:foldstack) && get(s:foldstack,0).lastline == s:lnum-1
+         let s:new = s:new."</span></span>"
+         call remove(s:foldstack, 0)
+       endwhile
+ 
+       " Now open any new folds that start on this line
+       let s:firstfold = 1
+       while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum
+         let s:foldId = s:foldId + 1
+         let s:new = s:new . "<span id='fold".s:foldId."' class='".s:allfolds[0].type."'>"
+ 
+         if !exists("html_no_foldcolumn")
+           " add fold column to 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."\")'>"
+             let s:new = s:new . repeat('|', s:allfolds[0].level - 1) . "</a>"
+           endif
+           let s:new = s:new . "<a class='toggle-open FoldColumn' href='javascript:toggleFold(\"fold".s:foldId."\")'>+"
+           let s:new = s:new . repeat(" ", s:foldcolumn - s:allfolds[0].level) . "</a>"
+ 
+           " add fold column to close the new fold
+           let s:new = s:new . "<a class='toggle-closed FoldColumn' href='javascript:toggleFold(\"fold".s:foldId."\")'>"
+           if s:firstfold
+             let s:new = s:new . repeat('|', s:allfolds[0].level - 1)
+           endif
+           let s:new = s:new . "-"
+           " only add a space if we aren't opening another fold on the same line
+           if get(s:allfolds, 1, {'firstline': 0}).firstline != s:lnum
+             let s:new = s:new . repeat(" ", s:foldcolumn - s:allfolds[0].level)
+           endif
+           let s:new = s:new . "</a>"
+           let s:firstfold = 0
+         endif
+ 
+         " add fold text, moving the span ending to the next line so collapsing
+         " works correctly
+         let s:new = s:new . substitute(s:HtmlFormat(s:numcol . foldtextresult(s:lnum), "Folded"), '</span>', s:HtmlEndline.'\r\0', '')
+         let s:new = s:new . "<span class='fulltext'>"
+ 
+         " open the fold now that we have the fold text to allow retrieval of
+         " fold text for subsequent folds
+         execute s:lnum."foldopen"
+         call insert(s:foldstack, remove(s:allfolds,0))
+         let s:foldstack[0].id = s:foldId
+       endwhile
+ 
+       if !exists("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")
+         else
+           " add the fold column for folds not on the opening line
+           if get(s:foldstack, 0).firstline < s:lnum
+             let s:new = s:new . "<a class='FoldColumn' href='javascript:toggleFold(\"fold".s:foldstack[0].id."\")'>"
+             let s:new = s:new . repeat('|', s:foldstack[0].level)
+             let s:new = s:new . repeat(' ', s:foldcolumn - s:foldstack[0].level) . "</a>"
+           endif
+         endif
+       endif
+     endif
+ 
+     " Now continue with the unfolded line text
      if s:numblines
!       let s:new = s:new . s:HtmlFormat(s:numcol, "lnr")
      endif
  
      " Get the diff attribute, if any.
***************
*** 378,399 ****
      while s:col <= s:len || (s:col == 1 && s:diffattr)
        let s:startcol = s:col " The start column for processing text
        if s:diffattr
! 	let s:id = diff_hlID(s:lnum, s:col)
! 	let s:col = s:col + 1
! 	" 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")
! 	  " 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
! 	endif
        else
! 	let s:id = synID(s:lnum, s:col, 1)
! 	let s:col = s:col + 1
! 	" Speed loop (it's small - that's the trick)
! 	" Go along till we find a change in synID
! 	while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
        endif
  
        " Expand tabs
--- 653,674 ----
      while s:col <= s:len || (s:col == 1 && s:diffattr)
        let s:startcol = s:col " The start column for processing text
        if s:diffattr
!         let s:id = diff_hlID(s:lnum, s:col)
!         let s:col = s:col + 1
!         " 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")
!           " 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
!         endif
        else
!         let s:id = synID(s:lnum, s:col, 1)
!         let s:col = s:col + 1
!         " Speed loop (it's small - that's the trick)
!         " Go along till we find a change in synID
!         while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
        endif
  
        " Expand tabs
***************
*** 401,424 ****
        let s:offset = 0
        let s:idx = stridx(s:expandedtab, "\t")
        while s:idx >= 0
! 	if has("multi_byte_encoding")
! 	  if s:startcol + s:idx == 1
! 	    let s:i = &ts
! 	  else
! 	    if s:idx == 0
! 	      let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c')
! 	    else
! 	      let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c')
! 	    endif
! 	    let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)])
! 	    let s:i = &ts - (s:vcol % &ts)
! 	  endif
! 	  let s:offset -= s:i - 1
! 	else
! 	  let s:i = &ts - ((s:idx + s:startcol - 1) % &ts)
! 	endif
! 	let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '')
! 	let s:idx = stridx(s:expandedtab, "\t")
        endwhile
  
        " Output the text with the same synID, with class set to {s:id_name}
--- 676,699 ----
        let s:offset = 0
        let s:idx = stridx(s:expandedtab, "\t")
        while s:idx >= 0
!         if has("multi_byte_encoding")
!           if s:startcol + s:idx == 1
!             let s:i = &ts
!           else
!             if s:idx == 0
!               let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c')
!             else
!               let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c')
!             endif
!             let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)])
!             let s:i = &ts - (s:vcol % &ts)
!           endif
!           let s:offset -= s:i - 1
!         else
!           let s:i = &ts - ((s:idx + s:startcol - 1) % &ts)
!         endif
!         let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '')
!         let s:idx = stridx(s:expandedtab, "\t")
        endwhile
  
        " Output the text with the same synID, with class set to {s:id_name}
***************
*** 436,443 ****
  " Finish with the last line
  exe s:newwin . "wincmd w"
  
  " Close off the font tag that encapsulates the whole <body>
! if !exists("html_use_css")
    exe "normal! a</font>\e"
  endif
  
--- 711,732 ----
  " Finish with the last line
  exe s:newwin . "wincmd w"
  
+ if exists("s:html_dynamic_folds")
+   " finish off any open folds
+   while !empty(s:foldstack)
+     exe "normal! a</span></span>"
+     call remove(s:foldstack, 0)
+   endwhile
+ 
+   " add fold column to the style list if not already there
+   let s:id = hlID('FoldColumn')
+   if stridx(s:idlist, "," . s:id . ",") == -1
+     let s:idlist = s:idlist . s:id . ","
+   endif
+ endif
+ 
  " Close off the font tag that encapsulates the whole <body>
! if !exists("s:html_use_css")
    exe "normal! a</font>\e"
  endif
  
***************
*** 449,455 ****
  
  
  " Now, when we finally know which, we define the colors and styles
! if exists("html_use_css")
    1;/<style type="text/+1
  endif
  
--- 738,744 ----
  
  
  " Now, when we finally know which, we define the colors and styles
! if exists("s:html_use_css")
    1;/<style type="text/+1
  endif
  
***************
*** 466,472 ****
  " Normal/global attributes
  " For Netscape 4, set <body> attributes too, though, strictly speaking, it's
  " incorrect.
! if exists("html_use_css")
    if exists("html_no_pre")
      execute "normal! A\nbody { color: " . s:fgc . "; background-color: " . s:bgc . "; font-family: ". s:htmlfont ."; }\e"
    else
--- 755,761 ----
  " Normal/global attributes
  " For Netscape 4, set <body> attributes too, though, strictly speaking, it's
  " incorrect.
! if exists("s:html_use_css")
    if exists("html_no_pre")
      execute "normal! A\nbody { color: " . s:fgc . "; background-color: " . s:bgc . "; font-family: ". s:htmlfont ."; }\e"
    else
***************
*** 476,487 ****
      execute "normal! ^cwbody\e"
    endif
  else
!     execute '%s:<body>:<body bgcolor="' . s:bgc . '" text="' . s:fgc . '"><font face="'. s:htmlfont .'">'
  endif
  
  " Line numbering attributes
  if s:numblines
!   if exists("html_use_css")
      execute "normal! A\n.lnr { " . s:CSS1(hlID("LineNr")) . "}\e"
    else
      execute '%s+^<span class="lnr">\([^<]*\)</span>+' . s:HtmlOpening(hlID("LineNr")) . '\1' . s:HtmlClosing(hlID("LineNr")) . '+g'
--- 765,776 ----
      execute "normal! ^cwbody\e"
    endif
  else
!   execute '%s:<body>:<body bgcolor="' . s:bgc . '" text="' . s:fgc . '"><font face="'. s:htmlfont .'">'
  endif
  
  " Line numbering attributes
  if s:numblines
!   if exists("s:html_use_css")
      execute "normal! A\n.lnr { " . s:CSS1(hlID("LineNr")) . "}\e"
    else
      execute '%s+^<span class="lnr">\([^<]*\)</span>+' . s:HtmlOpening(hlID("LineNr")) . '\1' . s:HtmlClosing(hlID("LineNr")) . '+g'
***************
*** 500,513 ****
    " If the class has some attributes, export the style, otherwise DELETE all
    " its occurences to make the HTML shorter
    if s:attr != ""
!     if exists("html_use_css")
        execute "normal! A\n." . s:id_name . " { " . s:attr . "}"
      else
        execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+' . s:HtmlOpening(s:id) . '\1' . s:HtmlClosing(s:id) . '+g'
      endif
    else
      execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+\1+ge'
!     if exists("html_use_css")
        1;/<style type="text/+1
      endif
    endif
--- 789,802 ----
    " If the class has some attributes, export the style, otherwise DELETE all
    " its occurences to make the HTML shorter
    if s:attr != ""
!     if exists("s:html_use_css")
        execute "normal! A\n." . s:id_name . " { " . s:attr . "}"
      else
        execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+' . s:HtmlOpening(s:id) . '\1' . s:HtmlClosing(s:id) . '+g'
      endif
    else
      execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+\1+ge'
!     if exists("s:html_use_css")
        1;/<style type="text/+1
      endif
    endif
***************
*** 554,567 ****
  unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search
  unlet s:whatterm s:idlist s:lnum s:end s:margin s:fgc s:bgc s:old_magic
  unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:numblines
! unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset
  if !v:profiling
    delfunc s:HtmlColor
    delfunc s:HtmlFormat
    delfunc s:CSS1
!   if !exists("html_use_css")
      delfunc s:HtmlOpening
      delfunc s:HtmlClosing
    endif
  endif
! silent! unlet s:diffattr s:difffillchar s:foldfillchar s:HtmlSpace s:LeadingSpace s:HtmlEndline
--- 843,868 ----
  unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search
  unlet s:whatterm s:idlist s:lnum s:end s:margin s:fgc s:bgc s:old_magic
  unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:numblines
! unlet s:orgwin s:newwin s:orgbufnr
  if !v:profiling
    delfunc s:HtmlColor
    delfunc s:HtmlFormat
    delfunc s:CSS1
!   if !exists("s:html_use_css")
      delfunc s:HtmlOpening
      delfunc s:HtmlClosing
    endif
  endif
! silent! unlet s:diffattr s:difffillchar s:foldfillchar s:HtmlSpace s:LeadingSpace s:HtmlEndline s:firstfold s:foldcolumn
! unlet s:foldstack s:allfolds s:foldId s:numcol
! 
! if exists("s:html_dynamic_folds")
!   delfunc s:FoldCompare
! endif
! 
! silent! unlet s:html_dynamic_folds s:html_hover_unfold s:html_use_css
! 
! let &cpo = s:cpo_sav
! unlet s:cpo_sav
! 
! " vim: et sw=2 sts=2
