2html.vim 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987
  1. " Vim syntax support file
  2. " Maintainer: Ben Fritz <fritzophrenic@gmail.com>
  3. " Last Change: 2020 Jan 05
  4. "
  5. " Additional contributors:
  6. "
  7. " Original by Bram Moolenaar <Bram@vim.org>
  8. " Modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>
  9. " XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>
  10. " Made w3 compliant by Edd Barrett <vext01@gmail.com>
  11. " Added html_font. Edd Barrett <vext01@gmail.com>
  12. " Progress bar based off code from "progressbar widget" plugin by
  13. " Andreas Politz, heavily modified:
  14. " http://www.vim.org/scripts/script.php?script_id=2006
  15. "
  16. " See Mercurial change logs for more!
  17. " Transform a file into HTML, using the current syntax highlighting.
  18. " this file uses line continuations
  19. let s:cpo_sav = &cpo
  20. let s:ls = &ls
  21. let s:ei_sav = &eventignore
  22. set cpo&vim
  23. " HTML filetype can take a while to load/highlight if the destination file
  24. " already exists.
  25. set eventignore+=FileType
  26. let s:end=line('$')
  27. " Font
  28. if exists("g:html_font")
  29. if type(g:html_font) == type([])
  30. let s:htmlfont = "'". join(g:html_font,"','") . "', monospace"
  31. else
  32. let s:htmlfont = "'". g:html_font . "', monospace"
  33. endif
  34. else
  35. let s:htmlfont = "monospace"
  36. endif
  37. let s:settings = tohtml#GetUserSettings()
  38. if s:settings.use_xhtml
  39. let s:html5 = 0
  40. elseif s:settings.use_css && !s:settings.no_pre
  41. let s:html5 = 1
  42. else
  43. let s:html5 = 0
  44. endif
  45. if !exists('s:FOLDED_ID')
  46. let s:FOLDED_ID = hlID("Folded") | lockvar s:FOLDED_ID
  47. let s:FOLD_C_ID = hlID("FoldColumn") | lockvar s:FOLD_C_ID
  48. let s:LINENR_ID = hlID('LineNr') | lockvar s:LINENR_ID
  49. let s:DIFF_D_ID = hlID("DiffDelete") | lockvar s:DIFF_D_ID
  50. let s:DIFF_A_ID = hlID("DiffAdd") | lockvar s:DIFF_A_ID
  51. let s:DIFF_C_ID = hlID("DiffChange") | lockvar s:DIFF_C_ID
  52. let s:DIFF_T_ID = hlID("DiffText") | lockvar s:DIFF_T_ID
  53. let s:CONCEAL_ID = hlID('Conceal') | lockvar s:CONCEAL_ID
  54. endif
  55. " Whitespace
  56. if s:settings.pre_wrap
  57. let s:whitespace = "white-space: pre-wrap; "
  58. else
  59. let s:whitespace = ""
  60. endif
  61. if !empty(s:settings.prevent_copy)
  62. if s:settings.no_invalid
  63. " User has decided they don't want invalid markup. Still works in
  64. " OpenOffice, and for text editors, but when pasting into Microsoft Word the
  65. " input elements get pasted too and they cannot be deleted (at least not
  66. " easily).
  67. let s:unselInputType = ""
  68. else
  69. " Prevent from copy-pasting the input elements into Microsoft Word where
  70. " they cannot be deleted easily by deliberately inserting invalid markup.
  71. let s:unselInputType = " type='invalid_input_type'"
  72. endif
  73. endif
  74. " When gui colors are not supported, we can only guess the colors.
  75. " TODO - is this true anymore? Is there a way to ask the terminal what colors
  76. " each number means or read them from some file?
  77. if &termguicolors || has("gui_running")
  78. let s:whatterm = "gui"
  79. else
  80. let s:whatterm = "cterm"
  81. if &t_Co == 8
  82. let s:cterm_color = {
  83. \ 0: "#808080", 1: "#ff6060", 2: "#00ff00", 3: "#ffff00",
  84. \ 4: "#8080ff", 5: "#ff40ff", 6: "#00ffff", 7: "#ffffff"
  85. \ }
  86. else
  87. let s:cterm_color = {
  88. \ 0: "#000000", 1: "#c00000", 2: "#008000", 3: "#804000",
  89. \ 4: "#0000c0", 5: "#c000c0", 6: "#008080", 7: "#c0c0c0",
  90. \ 8: "#808080", 9: "#ff6060", 10: "#00ff00", 11: "#ffff00",
  91. \ 12: "#8080ff", 13: "#ff40ff", 14: "#00ffff", 15: "#ffffff"
  92. \ }
  93. " Colors for 88 and 256 come from xterm.
  94. if &t_Co == 88
  95. call extend(s:cterm_color, {
  96. \ 16: "#000000", 17: "#00008b", 18: "#0000cd", 19: "#0000ff",
  97. \ 20: "#008b00", 21: "#008b8b", 22: "#008bcd", 23: "#008bff",
  98. \ 24: "#00cd00", 25: "#00cd8b", 26: "#00cdcd", 27: "#00cdff",
  99. \ 28: "#00ff00", 29: "#00ff8b", 30: "#00ffcd", 31: "#00ffff",
  100. \ 32: "#8b0000", 33: "#8b008b", 34: "#8b00cd", 35: "#8b00ff",
  101. \ 36: "#8b8b00", 37: "#8b8b8b", 38: "#8b8bcd", 39: "#8b8bff",
  102. \ 40: "#8bcd00", 41: "#8bcd8b", 42: "#8bcdcd", 43: "#8bcdff",
  103. \ 44: "#8bff00", 45: "#8bff8b", 46: "#8bffcd", 47: "#8bffff",
  104. \ 48: "#cd0000", 49: "#cd008b", 50: "#cd00cd", 51: "#cd00ff",
  105. \ 52: "#cd8b00", 53: "#cd8b8b", 54: "#cd8bcd", 55: "#cd8bff",
  106. \ 56: "#cdcd00", 57: "#cdcd8b", 58: "#cdcdcd", 59: "#cdcdff",
  107. \ 60: "#cdff00", 61: "#cdff8b", 62: "#cdffcd", 63: "#cdffff",
  108. \ 64: "#ff0000"
  109. \ })
  110. call extend(s:cterm_color, {
  111. \ 65: "#ff008b", 66: "#ff00cd", 67: "#ff00ff", 68: "#ff8b00",
  112. \ 69: "#ff8b8b", 70: "#ff8bcd", 71: "#ff8bff", 72: "#ffcd00",
  113. \ 73: "#ffcd8b", 74: "#ffcdcd", 75: "#ffcdff", 76: "#ffff00",
  114. \ 77: "#ffff8b", 78: "#ffffcd", 79: "#ffffff", 80: "#2e2e2e",
  115. \ 81: "#5c5c5c", 82: "#737373", 83: "#8b8b8b", 84: "#a2a2a2",
  116. \ 85: "#b9b9b9", 86: "#d0d0d0", 87: "#e7e7e7"
  117. \ })
  118. elseif &t_Co == 256
  119. call extend(s:cterm_color, {
  120. \ 16: "#000000", 17: "#00005f", 18: "#000087", 19: "#0000af",
  121. \ 20: "#0000d7", 21: "#0000ff", 22: "#005f00", 23: "#005f5f",
  122. \ 24: "#005f87", 25: "#005faf", 26: "#005fd7", 27: "#005fff",
  123. \ 28: "#008700", 29: "#00875f", 30: "#008787", 31: "#0087af",
  124. \ 32: "#0087d7", 33: "#0087ff", 34: "#00af00", 35: "#00af5f",
  125. \ 36: "#00af87", 37: "#00afaf", 38: "#00afd7", 39: "#00afff",
  126. \ 40: "#00d700", 41: "#00d75f", 42: "#00d787", 43: "#00d7af",
  127. \ 44: "#00d7d7", 45: "#00d7ff", 46: "#00ff00", 47: "#00ff5f",
  128. \ 48: "#00ff87", 49: "#00ffaf", 50: "#00ffd7", 51: "#00ffff",
  129. \ 52: "#5f0000", 53: "#5f005f", 54: "#5f0087", 55: "#5f00af",
  130. \ 56: "#5f00d7", 57: "#5f00ff", 58: "#5f5f00", 59: "#5f5f5f",
  131. \ 60: "#5f5f87", 61: "#5f5faf", 62: "#5f5fd7", 63: "#5f5fff",
  132. \ 64: "#5f8700"
  133. \ })
  134. call extend(s:cterm_color, {
  135. \ 65: "#5f875f", 66: "#5f8787", 67: "#5f87af", 68: "#5f87d7",
  136. \ 69: "#5f87ff", 70: "#5faf00", 71: "#5faf5f", 72: "#5faf87",
  137. \ 73: "#5fafaf", 74: "#5fafd7", 75: "#5fafff", 76: "#5fd700",
  138. \ 77: "#5fd75f", 78: "#5fd787", 79: "#5fd7af", 80: "#5fd7d7",
  139. \ 81: "#5fd7ff", 82: "#5fff00", 83: "#5fff5f", 84: "#5fff87",
  140. \ 85: "#5fffaf", 86: "#5fffd7", 87: "#5fffff", 88: "#870000",
  141. \ 89: "#87005f", 90: "#870087", 91: "#8700af", 92: "#8700d7",
  142. \ 93: "#8700ff", 94: "#875f00", 95: "#875f5f", 96: "#875f87",
  143. \ 97: "#875faf", 98: "#875fd7", 99: "#875fff", 100: "#878700",
  144. \ 101: "#87875f", 102: "#878787", 103: "#8787af", 104: "#8787d7",
  145. \ 105: "#8787ff", 106: "#87af00", 107: "#87af5f", 108: "#87af87",
  146. \ 109: "#87afaf", 110: "#87afd7", 111: "#87afff", 112: "#87d700"
  147. \ })
  148. call extend(s:cterm_color, {
  149. \ 113: "#87d75f", 114: "#87d787", 115: "#87d7af", 116: "#87d7d7",
  150. \ 117: "#87d7ff", 118: "#87ff00", 119: "#87ff5f", 120: "#87ff87",
  151. \ 121: "#87ffaf", 122: "#87ffd7", 123: "#87ffff", 124: "#af0000",
  152. \ 125: "#af005f", 126: "#af0087", 127: "#af00af", 128: "#af00d7",
  153. \ 129: "#af00ff", 130: "#af5f00", 131: "#af5f5f", 132: "#af5f87",
  154. \ 133: "#af5faf", 134: "#af5fd7", 135: "#af5fff", 136: "#af8700",
  155. \ 137: "#af875f", 138: "#af8787", 139: "#af87af", 140: "#af87d7",
  156. \ 141: "#af87ff", 142: "#afaf00", 143: "#afaf5f", 144: "#afaf87",
  157. \ 145: "#afafaf", 146: "#afafd7", 147: "#afafff", 148: "#afd700",
  158. \ 149: "#afd75f", 150: "#afd787", 151: "#afd7af", 152: "#afd7d7",
  159. \ 153: "#afd7ff", 154: "#afff00", 155: "#afff5f", 156: "#afff87",
  160. \ 157: "#afffaf", 158: "#afffd7"
  161. \ })
  162. call extend(s:cterm_color, {
  163. \ 159: "#afffff", 160: "#d70000", 161: "#d7005f", 162: "#d70087",
  164. \ 163: "#d700af", 164: "#d700d7", 165: "#d700ff", 166: "#d75f00",
  165. \ 167: "#d75f5f", 168: "#d75f87", 169: "#d75faf", 170: "#d75fd7",
  166. \ 171: "#d75fff", 172: "#d78700", 173: "#d7875f", 174: "#d78787",
  167. \ 175: "#d787af", 176: "#d787d7", 177: "#d787ff", 178: "#d7af00",
  168. \ 179: "#d7af5f", 180: "#d7af87", 181: "#d7afaf", 182: "#d7afd7",
  169. \ 183: "#d7afff", 184: "#d7d700", 185: "#d7d75f", 186: "#d7d787",
  170. \ 187: "#d7d7af", 188: "#d7d7d7", 189: "#d7d7ff", 190: "#d7ff00",
  171. \ 191: "#d7ff5f", 192: "#d7ff87", 193: "#d7ffaf", 194: "#d7ffd7",
  172. \ 195: "#d7ffff", 196: "#ff0000", 197: "#ff005f", 198: "#ff0087",
  173. \ 199: "#ff00af", 200: "#ff00d7", 201: "#ff00ff", 202: "#ff5f00",
  174. \ 203: "#ff5f5f", 204: "#ff5f87"
  175. \ })
  176. call extend(s:cterm_color, {
  177. \ 205: "#ff5faf", 206: "#ff5fd7", 207: "#ff5fff", 208: "#ff8700",
  178. \ 209: "#ff875f", 210: "#ff8787", 211: "#ff87af", 212: "#ff87d7",
  179. \ 213: "#ff87ff", 214: "#ffaf00", 215: "#ffaf5f", 216: "#ffaf87",
  180. \ 217: "#ffafaf", 218: "#ffafd7", 219: "#ffafff", 220: "#ffd700",
  181. \ 221: "#ffd75f", 222: "#ffd787", 223: "#ffd7af", 224: "#ffd7d7",
  182. \ 225: "#ffd7ff", 226: "#ffff00", 227: "#ffff5f", 228: "#ffff87",
  183. \ 229: "#ffffaf", 230: "#ffffd7", 231: "#ffffff", 232: "#080808",
  184. \ 233: "#121212", 234: "#1c1c1c", 235: "#262626", 236: "#303030",
  185. \ 237: "#3a3a3a", 238: "#444444", 239: "#4e4e4e", 240: "#585858",
  186. \ 241: "#626262", 242: "#6c6c6c", 243: "#767676", 244: "#808080",
  187. \ 245: "#8a8a8a", 246: "#949494", 247: "#9e9e9e", 248: "#a8a8a8",
  188. \ 249: "#b2b2b2", 250: "#bcbcbc", 251: "#c6c6c6", 252: "#d0d0d0",
  189. \ 253: "#dadada", 254: "#e4e4e4", 255: "#eeeeee"
  190. \ })
  191. endif
  192. endif
  193. endif
  194. " Return good color specification: in GUI no transformation is done, in
  195. " terminal return RGB values of known colors and empty string for unknown
  196. if s:whatterm == "gui"
  197. function! s:HtmlColor(color)
  198. return a:color
  199. endfun
  200. else
  201. function! s:HtmlColor(color)
  202. if has_key(s:cterm_color, a:color)
  203. return s:cterm_color[a:color]
  204. else
  205. return ""
  206. endif
  207. endfun
  208. endif
  209. " Find out the background and foreground color for use later
  210. let s:fgc = s:HtmlColor(synIDattr(hlID("Normal"), "fg#", s:whatterm))
  211. let s:bgc = s:HtmlColor(synIDattr(hlID("Normal"), "bg#", s:whatterm))
  212. if s:fgc == ""
  213. let s:fgc = ( &background == "dark" ? "#ffffff" : "#000000" )
  214. endif
  215. if s:bgc == ""
  216. let s:bgc = ( &background == "dark" ? "#000000" : "#ffffff" )
  217. endif
  218. if !s:settings.use_css
  219. " Return opening HTML tag for given highlight id
  220. function! s:HtmlOpening(id, extra_attrs)
  221. let a = ""
  222. if synIDattr(a:id, "inverse")
  223. " For inverse, we always must set both colors (and exchange them)
  224. let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
  225. let a = a . '<span '.a:extra_attrs.'style="background-color: ' . ( x != "" ? x : s:fgc ) . '">'
  226. let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
  227. let a = a . '<font color="' . ( x != "" ? x : s:bgc ) . '">'
  228. else
  229. let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
  230. if x != ""
  231. let a = a . '<span '.a:extra_attrs.'style="background-color: ' . x . '">'
  232. elseif !empty(a:extra_attrs)
  233. let a = a . '<span '.a:extra_attrs.'>'
  234. endif
  235. let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
  236. if x != "" | let a = a . '<font color="' . x . '">' | endif
  237. endif
  238. if synIDattr(a:id, "bold") | let a = a . "<b>" | endif
  239. if synIDattr(a:id, "italic") | let a = a . "<i>" | endif
  240. if synIDattr(a:id, "underline") | let a = a . "<u>" | endif
  241. return a
  242. endfun
  243. " Return closing HTML tag for given highlight id
  244. function! s:HtmlClosing(id, has_extra_attrs)
  245. let a = ""
  246. if synIDattr(a:id, "underline") | let a = a . "</u>" | endif
  247. if synIDattr(a:id, "italic") | let a = a . "</i>" | endif
  248. if synIDattr(a:id, "bold") | let a = a . "</b>" | endif
  249. if synIDattr(a:id, "inverse")
  250. let a = a . '</font></span>'
  251. else
  252. let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
  253. if x != "" | let a = a . '</font>' | endif
  254. let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
  255. if x != "" || a:has_extra_attrs | let a = a . '</span>' | endif
  256. endif
  257. return a
  258. endfun
  259. endif
  260. " Use a different function for formatting based on user options. This way we
  261. " can avoid a lot of logic during the actual execution.
  262. "
  263. " Build the function line by line containing only what is needed for the options
  264. " in use for maximum code sharing with minimal branch logic for greater speed.
  265. "
  266. " Note, 'exec' commands do not recognize line continuations, so must concatenate
  267. " lines rather than continue them.
  268. if s:settings.use_css
  269. " save CSS to a list of rules to add to the output at the end of processing
  270. " first, get the style names we need
  271. let wrapperfunc_lines = [
  272. \ 'function! s:BuildStyleWrapper(style_id, diff_style_id, extra_attrs, text, make_unselectable, unformatted)',
  273. \ '',
  274. \ ' let l:style_name = synIDattr(a:style_id, "name", s:whatterm)'
  275. \ ]
  276. if &diff
  277. let wrapperfunc_lines += [
  278. \ ' let l:diff_style_name = synIDattr(a:diff_style_id, "name", s:whatterm)']
  279. " Add normal groups and diff groups to separate lists so we can order them to
  280. " allow diff highlight to override normal highlight
  281. " if primary style IS a diff style, grab it from the diff cache instead
  282. " (always succeeds because we pre-populate it)
  283. let wrapperfunc_lines += [
  284. \ '',
  285. \ ' if a:style_id == s:DIFF_D_ID || a:style_id == s:DIFF_A_ID ||'.
  286. \ ' a:style_id == s:DIFF_C_ID || a:style_id == s:DIFF_T_ID',
  287. \ ' let l:saved_style = get(s:diffstylelist,a:style_id)',
  288. \ ' else'
  289. \ ]
  290. endif
  291. " get primary style info from cache or build it on the fly if not found
  292. let wrapperfunc_lines += [
  293. \ ' let l:saved_style = get(s:stylelist,a:style_id)',
  294. \ ' if type(l:saved_style) == type(0)',
  295. \ ' unlet l:saved_style',
  296. \ ' let l:saved_style = s:CSS1(a:style_id)',
  297. \ ' if l:saved_style != ""',
  298. \ ' let l:saved_style = "." . l:style_name . " { " . l:saved_style . "}"',
  299. \ ' endif',
  300. \ ' let s:stylelist[a:style_id]= l:saved_style',
  301. \ ' endif'
  302. \ ]
  303. if &diff
  304. let wrapperfunc_lines += [ ' endif' ]
  305. endif
  306. " Build the wrapper tags around the text. It turns out that caching these
  307. " gives pretty much zero performance gain and adds a lot of logic.
  308. let wrapperfunc_lines += [
  309. \ '',
  310. \ ' if l:saved_style == "" && empty(a:extra_attrs)'
  311. \ ]
  312. if &diff
  313. let wrapperfunc_lines += [
  314. \ ' if a:diff_style_id <= 0'
  315. \ ]
  316. endif
  317. " no surroundings if neither primary nor diff style has any info
  318. let wrapperfunc_lines += [
  319. \ ' return a:text'
  320. \ ]
  321. if &diff
  322. " no primary style, but diff style
  323. let wrapperfunc_lines += [
  324. \ ' else',
  325. \ ' return "<span class=\"" .l:diff_style_name . "\">".a:text."</span>"',
  326. \ ' endif'
  327. \ ]
  328. endif
  329. " open tag for non-empty primary style
  330. let wrapperfunc_lines += [
  331. \ ' else']
  332. " non-empty primary style. handle either empty or non-empty diff style.
  333. "
  334. " separate the two classes by a space to apply them both if there is a diff
  335. " style name, unless the primary style is empty, then just use the diff style
  336. " name
  337. let diffstyle =
  338. \ (&diff ? '(a:diff_style_id <= 0 ? "" : " ". l:diff_style_name) .'
  339. \ : "")
  340. if s:settings.prevent_copy == ""
  341. let wrapperfunc_lines += [
  342. \ ' return "<span ".a:extra_attrs."class=\"" . l:style_name .'.diffstyle.'"\">".a:text."</span>"'
  343. \ ]
  344. else
  345. " New method: use generated content in the CSS. The only thing needed here
  346. " is a span with no content, with an attribute holding the desired text.
  347. "
  348. " Old method: use an <input> element when text is unsectable. This is still
  349. " used in conditional comments for Internet Explorer, where the new method
  350. " doesn't work.
  351. "
  352. " Wrap the <input> in a <span> to allow fixing the stupid bug in some fonts
  353. " which cause browsers to display a 1px gap between lines when these
  354. " <input>s have a background color (maybe not really a bug, this isn't
  355. " well-defined)
  356. "
  357. " use strwidth, because we care only about how many character boxes are
  358. " needed to size the input, we don't care how many characters (including
  359. " separately counted composing chars, from strchars()) or bytes (from
  360. " len())the string contains. strdisplaywidth() is not needed because none of
  361. " the unselectable groups can contain tab characters (fold column, fold
  362. " text, line number).
  363. "
  364. " Note, if maxlength property needs to be added in the future, it will need
  365. " to use strchars(), because HTML specifies that the maxlength parameter
  366. " uses the number of unique codepoints for its limit.
  367. let wrapperfunc_lines += [
  368. \ ' if a:make_unselectable',
  369. \ ' return "<span ".a:extra_attrs."class=\"" . l:style_name .'.diffstyle.'"\"'
  370. \ ]
  371. if s:settings.use_input_for_pc !=# 'all'
  372. let wrapperfunc_lines[-1] .= ' " . "data-" . l:style_name . "-content=\"".a:text."\"'
  373. endif
  374. let wrapperfunc_lines[-1] .= '>'
  375. if s:settings.use_input_for_pc !=# 'none'
  376. let wrapperfunc_lines[-1] .=
  377. \ '<input'.s:unselInputType.' class=\"" . l:style_name .'.diffstyle.'"\"'.
  378. \ ' value=\"".substitute(a:unformatted,''\s\+$'',"","")."\"'.
  379. \ ' onselect=''this.blur(); return false;'''.
  380. \ ' onmousedown=''this.blur(); return false;'''.
  381. \ ' onclick=''this.blur(); return false;'''.
  382. \ ' readonly=''readonly'''.
  383. \ ' size=\"".strwidth(a:unformatted)."\"'.
  384. \ (s:settings.use_xhtml ? '/' : '').'>'
  385. endif
  386. let wrapperfunc_lines[-1] .= '</span>"'
  387. let wrapperfunc_lines += [
  388. \ ' else',
  389. \ ' return "<span ".a:extra_attrs."class=\"" . l:style_name .'. diffstyle .'"\">".a:text."</span>"'
  390. \ ]
  391. endif
  392. let wrapperfunc_lines += [
  393. \ ' endif',
  394. \ 'endfun'
  395. \ ]
  396. else
  397. " Non-CSS method just needs the wrapper.
  398. "
  399. " Functions used to get opening/closing automatically return null strings if
  400. " no styles exist.
  401. if &diff
  402. let wrapperfunc_lines = [
  403. \ 'function! s:BuildStyleWrapper(style_id, diff_style_id, extra_attrs, text, unusedarg, unusedarg2)',
  404. \ ' return s:HtmlOpening(a:style_id, a:extra_attrs).(a:diff_style_id <= 0 ? "" :'.
  405. \ 's:HtmlOpening(a:diff_style_id, "")).a:text.'.
  406. \ '(a:diff_style_id <= 0 ? "" : s:HtmlClosing(a:diff_style_id, 0)).s:HtmlClosing(a:style_id, !empty(a:extra_attrs))',
  407. \ 'endfun'
  408. \ ]
  409. else
  410. let wrapperfunc_lines = [
  411. \ 'function! s:BuildStyleWrapper(style_id, diff_style_id, extra_attrs, text, unusedarg, unusedarg2)',
  412. \ ' return s:HtmlOpening(a:style_id, a:extra_attrs).a:text.s:HtmlClosing(a:style_id, !empty(a:extra_attrs))',
  413. \ 'endfun'
  414. \ ]
  415. endif
  416. endif
  417. " create the function we built line by line above
  418. exec join(wrapperfunc_lines, "\n")
  419. let s:diff_mode = &diff
  420. " Return HTML valid characters enclosed in a span of class style_name with
  421. " unprintable characters expanded and double spaces replaced as necessary.
  422. "
  423. " TODO: eliminate unneeded logic like done for BuildStyleWrapper
  424. function! s:HtmlFormat(text, style_id, diff_style_id, extra_attrs, make_unselectable)
  425. " Replace unprintable characters
  426. let unformatted = strtrans(a:text)
  427. let formatted = unformatted
  428. " Replace the reserved html characters
  429. let formatted = substitute(formatted, '&', '\&amp;', 'g')
  430. let formatted = substitute(formatted, '<', '\&lt;', 'g')
  431. let formatted = substitute(formatted, '>', '\&gt;', 'g')
  432. let formatted = substitute(formatted, '"', '\&quot;', 'g')
  433. " &apos; is not valid in HTML but it is in XHTML, so just use the numeric
  434. " reference for it instead. Needed because it could appear in quotes
  435. " especially if unselectable regions is turned on.
  436. let formatted = substitute(formatted, '"', '\&#0039;', 'g')
  437. " Replace a "form feed" character with HTML to do a page break
  438. " TODO: need to prevent this in unselectable areas? Probably it should never
  439. " BE in an unselectable area...
  440. let formatted = substitute(formatted, "\x0c", '<hr class="PAGE-BREAK">', 'g')
  441. " Replace double spaces, leading spaces, and trailing spaces if needed
  442. if ' ' != s:HtmlSpace
  443. let formatted = substitute(formatted, ' ', s:HtmlSpace . s:HtmlSpace, 'g')
  444. let formatted = substitute(formatted, '^ ', s:HtmlSpace, 'g')
  445. let formatted = substitute(formatted, ' \+$', s:HtmlSpace, 'g')
  446. endif
  447. " Enclose in the correct format
  448. return s:BuildStyleWrapper(a:style_id, a:diff_style_id, a:extra_attrs, formatted, a:make_unselectable, unformatted)
  449. endfun
  450. " set up functions to call HtmlFormat in certain ways based on whether the
  451. " element is supposed to be unselectable or not
  452. if s:settings.prevent_copy =~# 'n'
  453. if s:settings.number_lines
  454. if s:settings.line_ids
  455. function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
  456. if a:lnr > 0
  457. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, 'id="'.(exists('g:html_diff_win_num') ? 'W'.g:html_diff_win_num : "").'L'.a:lnr.s:settings.id_suffix.'" ', 1)
  458. else
  459. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
  460. endif
  461. endfun
  462. else
  463. function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
  464. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
  465. endfun
  466. endif
  467. elseif s:settings.line_ids
  468. " if lines are not being numbered the only reason this function gets called
  469. " is to put the line IDs on each line; "text" will be empty but lnr will
  470. " always be non-zero, however we don't want to use the <input> because that
  471. " won't work as nice for empty text
  472. function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
  473. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, 'id="'.(exists('g:html_diff_win_num') ? 'W'.g:html_diff_win_num : "").'L'.a:lnr.s:settings.id_suffix.'" ', 0)
  474. endfun
  475. endif
  476. else
  477. if s:settings.line_ids
  478. function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
  479. if a:lnr > 0
  480. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, 'id="'.(exists('g:html_diff_win_num') ? 'W'.g:html_diff_win_num : "").'L'.a:lnr.s:settings.id_suffix.'" ', 0)
  481. else
  482. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
  483. endif
  484. endfun
  485. else
  486. function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
  487. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
  488. endfun
  489. endif
  490. endif
  491. if s:settings.prevent_copy =~# 'd'
  492. function! s:HtmlFormat_d(text, style_id, diff_style_id)
  493. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
  494. endfun
  495. else
  496. function! s:HtmlFormat_d(text, style_id, diff_style_id)
  497. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
  498. endfun
  499. endif
  500. if s:settings.prevent_copy =~# 'f'
  501. if s:settings.use_input_for_pc ==# 'none'
  502. " Simply space-pad to the desired width inside the generated content (note
  503. " that the FoldColumn definition includes a whitespace:pre rule)
  504. function! s:FoldColumn_build(char, len, numfill, char2, class, click)
  505. return "<a href='#' class='".a:class."' onclick='".a:click."' data-FoldColumn-content='".
  506. \ repeat(a:char, a:len).a:char2.repeat(' ', a:numfill).
  507. \ "'></a>"
  508. endfun
  509. function! s:FoldColumn_fill()
  510. return s:HtmlFormat(repeat(' ', s:foldcolumn), s:FOLD_C_ID, 0, "", 1)
  511. endfun
  512. else
  513. " Note the <input> elements for fill spaces will have a single space for
  514. " content, to allow active cursor CSS selection to work.
  515. "
  516. " Wrap the whole thing in a span for the 1px padding workaround for gaps.
  517. "
  518. " Build the function line by line containing only what is needed for the
  519. " options in use for maximum code sharing with minimal branch logic for
  520. " greater speed.
  521. "
  522. " Note, 'exec' commands do not recognize line continuations, so must
  523. " concatenate lines rather than continue them.
  524. let build_fun_lines = [
  525. \ 'function! s:FoldColumn_build(char, len, numfill, char2, class, click)',
  526. \ ' let l:input_open = "<input readonly=''readonly''".s:unselInputType.'.
  527. \ ' " onselect=''this.blur(); return false;''".'.
  528. \ ' " onmousedown=''this.blur(); ".a:click." return false;''".'.
  529. \ ' " onclick=''return false;'' size=''".'.
  530. \ ' string(a:len + (empty(a:char2) ? 0 : 1) + a:numfill) .'.
  531. \ ' "'' "',
  532. \ ' let l:common_attrs = "class=''FoldColumn'' value=''"',
  533. \ ' let l:input_close = (s:settings.use_xhtml ? "'' />" : "''>")'
  534. \ ]
  535. if s:settings.use_input_for_pc ==# 'fallback'
  536. let build_fun_lines += [
  537. \ ' let l:gen_content_link ='.
  538. \ ' "<a href=''#'' class=''FoldColumn'' onclick=''".a:click."'' data-FoldColumn-content=''".'.
  539. \ ' repeat(a:char, a:len).a:char2.repeat('' '', a:numfill).'.
  540. \ ' "''></a>"'
  541. \ ]
  542. endif
  543. let build_fun_lines += [
  544. \ ' return "<span class=''".a:class."''>".'.
  545. \ ' l:input_open.l:common_attrs.repeat(a:char, a:len).(a:char2).'.
  546. \ ' l:input_close.'.
  547. \ (s:settings.use_input_for_pc ==# 'fallback' ? 'l:gen_content_link.' : "").
  548. \ ' "</span>"',
  549. \ 'endfun'
  550. \ ]
  551. " create the function we built line by line above
  552. exec join(build_fun_lines, "\n")
  553. function! s:FoldColumn_fill()
  554. return s:FoldColumn_build(' ', s:foldcolumn, 0, '', 'FoldColumn', '')
  555. endfun
  556. endif
  557. else
  558. " For normal fold columns, simply space-pad to the desired width (note that
  559. " the FoldColumn definition includes a whitespace:pre rule)
  560. function! s:FoldColumn_build(char, len, numfill, char2, class, click)
  561. return "<a href='#' class='".a:class."' onclick='".a:click."'>".
  562. \ repeat(a:char, a:len).a:char2.repeat(' ', a:numfill).
  563. \ "</a>"
  564. endfun
  565. function! s:FoldColumn_fill()
  566. return s:HtmlFormat(repeat(' ', s:foldcolumn), s:FOLD_C_ID, 0, "", 0)
  567. endfun
  568. endif
  569. if s:settings.prevent_copy =~# 't'
  570. " put an extra empty span at the end for dynamic folds, so the linebreak can
  571. " be surrounded. Otherwise do it as normal.
  572. "
  573. " TODO: isn't there a better way to do this, than placing it here and using a
  574. " substitute later?
  575. if s:settings.dynamic_folds
  576. function! s:HtmlFormat_t(text, style_id, diff_style_id)
  577. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) .
  578. \ s:HtmlFormat("", a:style_id, 0, "", 0)
  579. endfun
  580. else
  581. function! s:HtmlFormat_t(text, style_id, diff_style_id)
  582. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
  583. endfun
  584. endif
  585. else
  586. function! s:HtmlFormat_t(text, style_id, diff_style_id)
  587. return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
  588. endfun
  589. endif
  590. " Return CSS style describing given highlight id (can be empty)
  591. function! s:CSS1(id)
  592. let a = ""
  593. if synIDattr(a:id, "inverse")
  594. " For inverse, we always must set both colors (and exchange them)
  595. let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
  596. let a = a . "color: " . ( x != "" ? x : s:bgc ) . "; "
  597. let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
  598. let a = a . "background-color: " . ( x != "" ? x : s:fgc ) . "; "
  599. else
  600. let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
  601. if x != "" | let a = a . "color: " . x . "; " | endif
  602. let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
  603. if x != ""
  604. let a = a . "background-color: " . x . "; "
  605. " stupid hack because almost every browser seems to have at least one font
  606. " which shows 1px gaps between lines which have background
  607. let a = a . "padding-bottom: 1px; "
  608. elseif (a:id == s:FOLDED_ID || a:id == s:LINENR_ID || a:id == s:FOLD_C_ID) && !empty(s:settings.prevent_copy)
  609. " input elements default to a different color than the rest of the page
  610. let a = a . "background-color: " . s:bgc . "; "
  611. endif
  612. endif
  613. if synIDattr(a:id, "bold") | let a = a . "font-weight: bold; " | endif
  614. if synIDattr(a:id, "italic") | let a = a . "font-style: italic; " | endif
  615. if synIDattr(a:id, "underline") | let a = a . "text-decoration: underline; " | endif
  616. return a
  617. endfun
  618. if s:settings.dynamic_folds
  619. " compares two folds as stored in our list of folds
  620. " A fold is "less" than another if it starts at an earlier line number,
  621. " or ends at a later line number, ties broken by fold level
  622. function! s:FoldCompare(f1, f2)
  623. if a:f1.firstline != a:f2.firstline
  624. " put it before if it starts earlier
  625. return a:f1.firstline - a:f2.firstline
  626. elseif a:f1.lastline != a:f2.lastline
  627. " put it before if it ends later
  628. return a:f2.lastline - a:f1.lastline
  629. else
  630. " if folds begin and end on the same lines, put lowest fold level first
  631. return a:f1.level - a:f2.level
  632. endif
  633. endfunction
  634. endif
  635. " Set some options to make it work faster.
  636. " Don't report changes for :substitute, there will be many of them.
  637. " Don't change other windows; turn off scroll bind temporarily
  638. let s:old_title = &title
  639. let s:old_icon = &icon
  640. let s:old_et = &l:et
  641. let s:old_bind = &l:scrollbind
  642. let s:old_report = &report
  643. let s:old_search = @/
  644. let s:old_more = &more
  645. set notitle noicon
  646. setlocal et
  647. set nomore
  648. set report=1000000
  649. setlocal noscrollbind
  650. if exists(':ownsyntax') && exists('w:current_syntax')
  651. let s:current_syntax = w:current_syntax
  652. elseif exists('b:current_syntax')
  653. let s:current_syntax = b:current_syntax
  654. else
  655. let s:current_syntax = 'none'
  656. endif
  657. if s:current_syntax == ''
  658. let s:current_syntax = 'none'
  659. endif
  660. " If the user is sourcing this script directly then the plugin version isn't
  661. " known because the main plugin script didn't load. In the usual case where the
  662. " user still has the full Vim runtime installed, or has this full plugin
  663. " installed in a package or something, then we can extract the version from the
  664. " main plugin file at it's usual spot relative to this file. Otherwise the user
  665. " is assembling their runtime piecemeal and we have no idea what versions of
  666. " other files may be present so don't even try to make a guess or assume the
  667. " presence of other specific files with specific meaning.
  668. "
  669. " We don't want to actually source the main plugin file here because the user
  670. " may have a good reason not to (e.g. they define their own TOhtml command or
  671. " something).
  672. "
  673. " If this seems way too complicated and convoluted, it is. Probably I should
  674. " have put the version information in the autoload file from the start. But the
  675. " version has been in the global variable for so long that changing it could
  676. " break a lot of user scripts.
  677. if exists("g:loaded_2html_plugin")
  678. let s:pluginversion = g:loaded_2html_plugin
  679. else
  680. if !exists("g:unloaded_tohtml_plugin")
  681. let s:main_plugin_path = expand("<sfile>:p:h:h")."/plugin/tohtml.vim"
  682. if filereadable(s:main_plugin_path)
  683. let s:lines = readfile(s:main_plugin_path, "", 20)
  684. call filter(s:lines, 'v:val =~ "loaded_2html_plugin = "')
  685. if empty(s:lines)
  686. let g:unloaded_tohtml_plugin = "unknown"
  687. else
  688. let g:unloaded_tohtml_plugin = substitute(s:lines[0], '.*loaded_2html_plugin = \([''"]\)\(\%(\1\@!.\)\+\)\1', '\2', '')
  689. endif
  690. unlet s:lines
  691. else
  692. let g:unloaded_tohtml_plugin = "unknown"
  693. endif
  694. unlet s:main_plugin_path
  695. endif
  696. let s:pluginversion = g:unloaded_tohtml_plugin
  697. endif
  698. " Split window to create a buffer with the HTML file.
  699. let s:orgbufnr = winbufnr(0)
  700. let s:origwin_stl = &l:stl
  701. if expand("%") == ""
  702. if exists('g:html_diff_win_num')
  703. exec 'new Untitled_win'.g:html_diff_win_num.'.'.(s:settings.use_xhtml ? 'x' : '').'html'
  704. else
  705. exec 'new Untitled.'.(s:settings.use_xhtml ? 'x' : '').'html'
  706. endif
  707. else
  708. exec 'new %.'.(s:settings.use_xhtml ? 'x' : '').'html'
  709. endif
  710. " Resize the new window to very small in order to make it draw faster
  711. let s:old_winheight = winheight(0)
  712. let s:old_winfixheight = &l:winfixheight
  713. if s:old_winheight > 2
  714. resize 1 " leave enough room to view one line at a time
  715. norm! G
  716. norm! zt
  717. endif
  718. setlocal winfixheight
  719. let s:newwin_stl = &l:stl
  720. " on the new window, set the least time-consuming fold method
  721. let s:old_fen = &foldenable
  722. setlocal foldmethod=manual
  723. setlocal nofoldenable
  724. let s:newwin = winnr()
  725. let s:orgwin = bufwinnr(s:orgbufnr)
  726. setlocal modifiable
  727. %d
  728. let s:old_paste = &paste
  729. set paste
  730. let s:old_magic = &magic
  731. set magic
  732. " set the fileencoding to match the charset we'll be using
  733. let &l:fileencoding=s:settings.vim_encoding
  734. " According to http://www.w3.org/TR/html4/charset.html#doc-char-set, the byte
  735. " order mark is highly recommend on the web when using multibyte encodings. But,
  736. " it is not a good idea to include it on UTF-8 files. Otherwise, let Vim
  737. " determine when it is actually inserted.
  738. if s:settings.vim_encoding == 'utf-8'
  739. setlocal nobomb
  740. else
  741. setlocal bomb
  742. endif
  743. let s:lines = []
  744. if s:settings.use_xhtml
  745. if s:settings.encoding != ""
  746. call add(s:lines, "<?xml version=\"1.0\" encoding=\"" . s:settings.encoding . "\"?>")
  747. else
  748. call add(s:lines, "<?xml version=\"1.0\"?>")
  749. endif
  750. let s:tag_close = ' />'
  751. else
  752. let s:tag_close = '>'
  753. endif
  754. let s:HtmlSpace = ' '
  755. let s:LeadingSpace = ' '
  756. let s:HtmlEndline = ''
  757. if s:settings.no_pre
  758. let s:HtmlEndline = '<br' . s:tag_close
  759. let s:LeadingSpace = s:settings.use_xhtml ? '&#160;' : '&nbsp;'
  760. let s:HtmlSpace = '\' . s:LeadingSpace
  761. endif
  762. " HTML header, with the title and generator ;-). Left free space for the CSS,
  763. " to be filled at the end.
  764. call extend(s:lines, [
  765. \ "<html>",
  766. \ "<head>"])
  767. " include encoding as close to the top as possible, but only if not already
  768. " contained in XML information (to avoid haggling over content type)
  769. if s:settings.encoding != "" && !s:settings.use_xhtml
  770. if s:html5
  771. call add(s:lines, '<meta charset="' . s:settings.encoding . '"' . s:tag_close)
  772. else
  773. call add(s:lines, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:settings.encoding . '"' . s:tag_close)
  774. endif
  775. endif
  776. call extend(s:lines, [
  777. \ ("<title>".expand("%:p:~")."</title>"),
  778. \ ("<meta name=\"Generator\" content=\"Vim/".v:version/100.".".v:version%100.'"'.s:tag_close),
  779. \ ("<meta name=\"plugin-version\" content=\"".s:pluginversion.'"'.s:tag_close)
  780. \ ])
  781. call add(s:lines, '<meta name="syntax" content="'.s:current_syntax.'"'.s:tag_close)
  782. call add(s:lines, '<meta name="settings" content="'.
  783. \ join(filter(keys(s:settings),'s:settings[v:val]'),',').
  784. \ ',prevent_copy='.s:settings.prevent_copy.
  785. \ ',use_input_for_pc='.s:settings.use_input_for_pc.
  786. \ '"'.s:tag_close)
  787. call add(s:lines, '<meta name="colorscheme" content="'.
  788. \ (exists('g:colors_name')
  789. \ ? g:colors_name
  790. \ : 'none'). '"'.s:tag_close)
  791. if s:settings.use_css
  792. call extend(s:lines, [
  793. \ "<style" . (s:html5 ? "" : " type=\"text/css\"") . ">",
  794. \ s:settings.use_xhtml ? "" : "<!--"])
  795. let s:ieonly = []
  796. if s:settings.dynamic_folds
  797. if s:settings.hover_unfold
  798. " if we are doing hover_unfold, use css 2 with css 1 fallback for IE6
  799. call extend(s:lines, [
  800. \ ".FoldColumn { text-decoration: none; white-space: pre; }",
  801. \ "",
  802. \ "body * { margin: 0; padding: 0; }", "",
  803. \ ".open-fold > span.Folded { display: none; }",
  804. \ ".open-fold > .fulltext { display: inline; }",
  805. \ ".closed-fold > .fulltext { display: none; }",
  806. \ ".closed-fold > span.Folded { display: inline; }",
  807. \ "",
  808. \ ".open-fold > .toggle-open { display: none; }",
  809. \ ".open-fold > .toggle-closed { display: inline; }",
  810. \ ".closed-fold > .toggle-open { display: inline; }",
  811. \ ".closed-fold > .toggle-closed { display: none; }",
  812. \ "", "",
  813. \ '/* opening a fold while hovering won''t be supported by IE6 and other',
  814. \ "similar browsers, but it should fail gracefully. */",
  815. \ ".closed-fold:hover > .fulltext { display: inline; }",
  816. \ ".closed-fold:hover > .toggle-filler { display: none; }",
  817. \ ".closed-fold:hover > .Folded { display: none; }"])
  818. " TODO: IE6 is REALLY old and I can't even test it anymore. Maybe we
  819. " should remove this? Leave it in for now, it was working at one point,
  820. " and doesn't affect any modern browsers. Even newer IE versions should
  821. " support the above code and ignore the following.
  822. let s:ieonly = [
  823. \ "<!--[if lt IE 7]><style type=\"text/css\">",
  824. \ ".open-fold .fulltext { display: inline; }",
  825. \ ".open-fold span.Folded { display: none; }",
  826. \ ".open-fold .toggle-open { display: none; }",
  827. \ ".open-fold .toggle-closed { display: inline; }",
  828. \ "",
  829. \ ".closed-fold .fulltext { display: none; }",
  830. \ ".closed-fold span.Folded { display: inline; }",
  831. \ ".closed-fold .toggle-open { display: inline; }",
  832. \ ".closed-fold .toggle-closed { display: none; }",
  833. \ "</style>",
  834. \ "<![endif]-->",
  835. \]
  836. else
  837. " if we aren't doing hover_unfold, use CSS 1 only
  838. call extend(s:lines, [
  839. \ ".FoldColumn { text-decoration: none; white-space: pre; }",
  840. \ ".open-fold .fulltext { display: inline; }",
  841. \ ".open-fold span.Folded { display: none; }",
  842. \ ".open-fold .toggle-open { display: none; }",
  843. \ ".open-fold .toggle-closed { display: inline; }",
  844. \ "",
  845. \ ".closed-fold .fulltext { display: none; }",
  846. \ ".closed-fold span.Folded { display: inline; }",
  847. \ ".closed-fold .toggle-open { display: inline; }",
  848. \ ".closed-fold .toggle-closed { display: none; }",
  849. \])
  850. endif
  851. endif
  852. " else we aren't doing any dynamic folding, no need for any special rules
  853. call extend(s:lines, [
  854. \ s:settings.use_xhtml ? "" : '-->',
  855. \ "</style>",
  856. \])
  857. call extend(s:lines, s:ieonly)
  858. unlet s:ieonly
  859. endif
  860. let s:uses_script = s:settings.dynamic_folds || s:settings.line_ids
  861. " insert script tag if needed
  862. if s:uses_script
  863. call extend(s:lines, [
  864. \ "",
  865. \ "<script" . (s:html5 ? "" : " type='text/javascript'") . ">",
  866. \ s:settings.use_xhtml ? '//<![CDATA[' : "<!--"])
  867. endif
  868. " insert javascript to toggle folds open and closed
  869. if s:settings.dynamic_folds
  870. call extend(s:lines, [
  871. \ "",
  872. \ "function toggleFold(objID)",
  873. \ "{",
  874. \ " var fold;",
  875. \ " fold = document.getElementById(objID);",
  876. \ " if (fold.className == 'closed-fold')",
  877. \ " {",
  878. \ " fold.className = 'open-fold';",
  879. \ " }",
  880. \ " else if (fold.className == 'open-fold')",
  881. \ " {",
  882. \ " fold.className = 'closed-fold';",
  883. \ " }",
  884. \ "}"
  885. \ ])
  886. endif
  887. if s:settings.line_ids
  888. " insert javascript to get IDs from line numbers, and to open a fold before
  889. " jumping to any lines contained therein
  890. call extend(s:lines, [
  891. \ "",
  892. \ "/* function to open any folds containing a jumped-to line before jumping to it */",
  893. \ "function JumpToLine()",
  894. \ "{",
  895. \ " var lineNum;",
  896. \ " lineNum = window.location.hash;",
  897. \ " lineNum = lineNum.substr(1); /* strip off '#' */",
  898. \ "",
  899. \ " if (lineNum.indexOf('L') == -1) {",
  900. \ " lineNum = 'L'+lineNum;",
  901. \ " }",
  902. \ " var lineElem = document.getElementById(lineNum);"
  903. \ ])
  904. if s:settings.dynamic_folds
  905. call extend(s:lines, [
  906. \ "",
  907. \ " /* navigate upwards in the DOM tree to open all folds containing the line */",
  908. \ " var node = lineElem;",
  909. \ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
  910. \ " {",
  911. \ " if (node.className == 'closed-fold')",
  912. \ " {",
  913. \ " node.className = 'open-fold';",
  914. \ " }",
  915. \ " node = node.parentNode;",
  916. \ " }",
  917. \ ])
  918. endif
  919. call extend(s:lines, [
  920. \ " /* Always jump to new location even if the line was hidden inside a fold, or",
  921. \ " * we corrected the raw number to a line ID.",
  922. \ " */",
  923. \ " if (lineElem) {",
  924. \ " lineElem.scrollIntoView(true);",
  925. \ " }",
  926. \ " return true;",
  927. \ "}",
  928. \ "if ('onhashchange' in window) {",
  929. \ " window.onhashchange = JumpToLine;",
  930. \ "}"
  931. \ ])
  932. endif
  933. " insert script closing tag if needed
  934. if s:uses_script
  935. call extend(s:lines, [
  936. \ '',
  937. \ s:settings.use_xhtml ? '//]]>' : '-->',
  938. \ "</script>"
  939. \ ])
  940. endif
  941. call extend(s:lines, ["</head>",
  942. \ "<body".(s:settings.line_ids ? " onload='JumpToLine();'" : "").">"])
  943. if s:settings.no_pre
  944. " if we're not using CSS we use a font tag which can't have a div inside
  945. if s:settings.use_css
  946. call extend(s:lines, ["<div id='vimCodeElement".s:settings.id_suffix."'>"])
  947. endif
  948. else
  949. call extend(s:lines, ["<pre id='vimCodeElement".s:settings.id_suffix."'>"])
  950. endif
  951. exe s:orgwin . "wincmd w"
  952. " caches of style data
  953. " initialize to include line numbers if using them
  954. if s:settings.number_lines
  955. let s:stylelist = { s:LINENR_ID : ".LineNr { " . s:CSS1( s:LINENR_ID ) . "}" }
  956. else
  957. let s:stylelist = {}
  958. endif
  959. let s:diffstylelist = {
  960. \ s:DIFF_A_ID : ".DiffAdd { " . s:CSS1( s:DIFF_A_ID ) . "}",
  961. \ s:DIFF_C_ID : ".DiffChange { " . s:CSS1( s:DIFF_C_ID ) . "}",
  962. \ s:DIFF_D_ID : ".DiffDelete { " . s:CSS1( s:DIFF_D_ID ) . "}",
  963. \ s:DIFF_T_ID : ".DiffText { " . s:CSS1( s:DIFF_T_ID ) . "}"
  964. \ }
  965. " set up progress bar in the status line
  966. if !s:settings.no_progress
  967. " ProgressBar Indicator
  968. let s:progressbar={}
  969. " Progressbar specific functions
  970. func! s:SetProgbarColor()
  971. if hlID("TOhtmlProgress") != 0
  972. hi! link TOhtmlProgress_auto TOhtmlProgress
  973. elseif hlID("TOhtmlProgress_auto")==0 ||
  974. \ !exists("s:last_colors_name") || !exists("g:colors_name") ||
  975. \ g:colors_name != s:last_colors_name
  976. let s:last_colors_name = exists("g:colors_name") ? g:colors_name : "none"
  977. let l:diffatr = synIDattr(hlID("DiffDelete"), "reverse", s:whatterm) ? "fg#" : "bg#"
  978. let l:stlatr = synIDattr(hlID("StatusLine"), "reverse", s:whatterm) ? "fg#" : "bg#"
  979. let l:progbar_color = synIDattr(hlID("DiffDelete"), l:diffatr, s:whatterm)
  980. let l:stl_color = synIDattr(hlID("StatusLine"), l:stlatr, s:whatterm)
  981. if "" == l:progbar_color
  982. let l:progbar_color = synIDattr(hlID("DiffDelete"), "reverse", s:whatterm) ? s:fgc : s:bgc
  983. endif
  984. if "" == l:stl_color
  985. let l:stl_color = synIDattr(hlID("StatusLine"), "reverse", s:whatterm) ? s:fgc : s:bgc
  986. endif
  987. if l:progbar_color == l:stl_color
  988. if s:whatterm == 'cterm'
  989. if l:progbar_color >= (&t_Co/2)
  990. let l:progbar_color-=1
  991. else
  992. let l:progbar_color+=1
  993. endif
  994. else
  995. let l:rgb = map(matchlist(l:progbar_color, '#\zs\x\x\ze\(\x\x\)\(\x\x\)')[:2], 'str2nr(v:val, 16)')
  996. let l:avg = (l:rgb[0] + l:rgb[1] + l:rgb[2])/3
  997. if l:avg >= 128
  998. let l:avg_new = l:avg
  999. while l:avg - l:avg_new < 0x15
  1000. let l:rgb = map(l:rgb, 'v:val * 3 / 4')
  1001. let l:avg_new = (l:rgb[0] + l:rgb[1] + l:rgb[2])/3
  1002. endwhile
  1003. else
  1004. let l:avg_new = l:avg
  1005. while l:avg_new - l:avg < 0x15
  1006. let l:rgb = map(l:rgb, 'min([max([v:val, 4]) * 5 / 4, 255])')
  1007. let l:avg_new = (l:rgb[0] + l:rgb[1] + l:rgb[2])/3
  1008. endwhile
  1009. endif
  1010. let l:progbar_color = printf("#%02x%02x%02x", l:rgb[0], l:rgb[1], l:rgb[2])
  1011. endif
  1012. echomsg "diff detected progbar color set to" l:progbar_color
  1013. endif
  1014. exe "hi TOhtmlProgress_auto" s:whatterm."bg=".l:progbar_color
  1015. endif
  1016. endfun
  1017. func! s:ProgressBar(title, max_value, winnr)
  1018. let pgb=copy(s:progressbar)
  1019. let pgb.title = a:title.' '
  1020. let pgb.max_value = a:max_value
  1021. let pgb.winnr = a:winnr
  1022. let pgb.cur_value = 0
  1023. let pgb.items = { 'title' : { 'color' : 'Statusline' },
  1024. \'bar' : { 'color' : 'Statusline' , 'fillcolor' : 'TOhtmlProgress_auto' , 'bg' : 'Statusline' } ,
  1025. \'counter' : { 'color' : 'Statusline' } }
  1026. let pgb.last_value = 0
  1027. let pgb.needs_redraw = 0
  1028. " Note that you must use len(split) instead of len() if you want to use
  1029. " unicode in title.
  1030. "
  1031. " Subtract 3 for spacing around the title.
  1032. " Subtract 4 for the percentage display.
  1033. " Subtract 2 for spacing before this.
  1034. " Subtract 2 more for the '|' on either side of the progress bar
  1035. let pgb.subtractedlen=len(split(pgb.title, '\zs'))+3+4+2+2
  1036. let pgb.max_len = 0
  1037. set laststatus=2
  1038. return pgb
  1039. endfun
  1040. " Function: progressbar.calculate_ticks() {{{1
  1041. func! s:progressbar.calculate_ticks(pb_len)
  1042. if a:pb_len<=0
  1043. let pb_len = 100
  1044. else
  1045. let pb_len = a:pb_len
  1046. endif
  1047. let self.progress_ticks = map(range(pb_len+1), "v:val * self.max_value / pb_len")
  1048. endfun
  1049. "Function: progressbar.paint()
  1050. func! s:progressbar.paint()
  1051. " Recalculate widths.
  1052. let max_len = winwidth(self.winnr)
  1053. let pb_len = 0
  1054. " always true on first call because of initial value of self.max_len
  1055. if max_len != self.max_len
  1056. let self.max_len = max_len
  1057. " Progressbar length
  1058. let pb_len = max_len - self.subtractedlen
  1059. call self.calculate_ticks(pb_len)
  1060. let self.needs_redraw = 1
  1061. let cur_value = 0
  1062. let self.pb_len = pb_len
  1063. else
  1064. " start searching at the last found index to make the search for the
  1065. " appropriate tick value normally take 0 or 1 comparisons
  1066. let cur_value = self.last_value
  1067. let pb_len = self.pb_len
  1068. endif
  1069. let cur_val_max = pb_len > 0 ? pb_len : 100
  1070. " find the current progress bar position based on precalculated thresholds
  1071. while cur_value < cur_val_max && self.cur_value > self.progress_ticks[cur_value]
  1072. let cur_value += 1
  1073. endwhile
  1074. " update progress bar
  1075. if self.last_value != cur_value || self.needs_redraw || self.cur_value == self.max_value
  1076. let self.needs_redraw = 1
  1077. let self.last_value = cur_value
  1078. let t_color = self.items.title.color
  1079. let b_fcolor = self.items.bar.fillcolor
  1080. let b_color = self.items.bar.color
  1081. let c_color = self.items.counter.color
  1082. let stl = "%#".t_color."#%-( ".self.title." %)".
  1083. \"%#".b_color."#".
  1084. \(pb_len>0 ?
  1085. \ ('|%#'.b_fcolor."#%-(".repeat(" ",cur_value)."%)".
  1086. \ '%#'.b_color."#".repeat(" ",pb_len-cur_value)."|"):
  1087. \ ('')).
  1088. \"%=%#".c_color."#%( ".printf("%3.d ",100*self.cur_value/self.max_value)."%% %)"
  1089. call setwinvar(self.winnr, '&stl', stl)
  1090. endif
  1091. endfun
  1092. func! s:progressbar.incr( ... )
  1093. let self.cur_value += (a:0 ? a:1 : 1)
  1094. " if we were making a general-purpose progress bar, we'd need to limit to a
  1095. " lower limit as well, but since we always increment with a positive value
  1096. " in this script, we only need limit the upper value
  1097. let self.cur_value = (self.cur_value > self.max_value ? self.max_value : self.cur_value)
  1098. call self.paint()
  1099. endfun
  1100. " }}}
  1101. if s:settings.dynamic_folds
  1102. " to process folds we make two passes through each line
  1103. let s:pgb = s:ProgressBar("Processing folds:", line('$')*2, s:orgwin)
  1104. endif
  1105. call s:SetProgbarColor()
  1106. endif
  1107. " First do some preprocessing for dynamic folding. Do this for the entire file
  1108. " so we don't accidentally start within a closed fold or something.
  1109. let s:allfolds = []
  1110. if s:settings.dynamic_folds
  1111. let s:lnum = 1
  1112. let s:end = line('$')
  1113. " save the fold text and set it to the default so we can find fold levels
  1114. let s:foldtext_save = &foldtext
  1115. setlocal foldtext&
  1116. " we will set the foldcolumn in the html to the greater of the maximum fold
  1117. " level and the current foldcolumn setting
  1118. let s:foldcolumn = &foldcolumn
  1119. " get all info needed to describe currently closed folds
  1120. while s:lnum <= s:end
  1121. if foldclosed(s:lnum) == s:lnum
  1122. " default fold text has '+-' and then a number of dashes equal to fold
  1123. " level, so subtract 2 from index of first non-dash after the dashes
  1124. " in order to get the fold level of the current fold
  1125. let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
  1126. " store fold info for later use
  1127. let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
  1128. call add(s:allfolds, s:newfold)
  1129. " open the fold so we can find any contained folds
  1130. execute s:lnum."foldopen"
  1131. else
  1132. if !s:settings.no_progress
  1133. call s:pgb.incr()
  1134. if s:pgb.needs_redraw
  1135. redrawstatus
  1136. let s:pgb.needs_redraw = 0
  1137. endif
  1138. endif
  1139. let s:lnum = s:lnum + 1
  1140. endif
  1141. endwhile
  1142. " close all folds to get info for originally open folds
  1143. silent! %foldclose!
  1144. let s:lnum = 1
  1145. " the originally open folds will be all folds we encounter that aren't
  1146. " already in the list of closed folds
  1147. while s:lnum <= s:end
  1148. if foldclosed(s:lnum) == s:lnum
  1149. " default fold text has '+-' and then a number of dashes equal to fold
  1150. " level, so subtract 2 from index of first non-dash after the dashes
  1151. " in order to get the fold level of the current fold
  1152. let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
  1153. let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
  1154. " only add the fold if we don't already have it
  1155. if empty(s:allfolds) || index(s:allfolds, s:newfold) == -1
  1156. let s:newfold.type = "open-fold"
  1157. call add(s:allfolds, s:newfold)
  1158. endif
  1159. " open the fold so we can find any contained folds
  1160. execute s:lnum."foldopen"
  1161. else
  1162. if !s:settings.no_progress
  1163. call s:pgb.incr()
  1164. if s:pgb.needs_redraw
  1165. redrawstatus
  1166. let s:pgb.needs_redraw = 0
  1167. endif
  1168. endif
  1169. let s:lnum = s:lnum + 1
  1170. endif
  1171. endwhile
  1172. " sort the folds so that we only ever need to look at the first item in the
  1173. " list of folds
  1174. call sort(s:allfolds, "s:FoldCompare")
  1175. let &l:foldtext = s:foldtext_save
  1176. unlet s:foldtext_save
  1177. " close all folds again so we can get the fold text as we go
  1178. silent! %foldclose!
  1179. " Go through and remove folds we don't need to (or cannot) process in the
  1180. " current conversion range
  1181. "
  1182. " If a fold is removed which contains other folds, which are included, we need
  1183. " to adjust the level of the included folds as used by the conversion logic
  1184. " (avoiding special cases is good)
  1185. "
  1186. " Note any time we remove a fold, either all of the included folds are in it,
  1187. " or none of them, because we only remove a fold if neither its start nor its
  1188. " end are within the conversion range.
  1189. let leveladjust = 0
  1190. for afold in s:allfolds
  1191. let removed = 0
  1192. if exists("g:html_start_line") && exists("g:html_end_line")
  1193. if afold.firstline < g:html_start_line
  1194. if afold.lastline <= g:html_end_line && afold.lastline >= g:html_start_line
  1195. " if a fold starts before the range to convert but stops within the
  1196. " range, we need to include it. Make it start on the first converted
  1197. " line.
  1198. let afold.firstline = g:html_start_line
  1199. else
  1200. " if the fold lies outside the range or the start and stop enclose
  1201. " the entire range, don't bother parsing it
  1202. call remove(s:allfolds, index(s:allfolds, afold))
  1203. let removed = 1
  1204. if afold.lastline > g:html_end_line
  1205. let leveladjust += 1
  1206. endif
  1207. endif
  1208. elseif afold.firstline > g:html_end_line
  1209. " If the entire fold lies outside the range we need to remove it.
  1210. call remove(s:allfolds, index(s:allfolds, afold))
  1211. let removed = 1
  1212. endif
  1213. elseif exists("g:html_start_line")
  1214. if afold.firstline < g:html_start_line
  1215. " if there is no last line, but there is a first line, the end of the
  1216. " fold will always lie within the region of interest, so keep it
  1217. let afold.firstline = g:html_start_line
  1218. endif
  1219. elseif exists("g:html_end_line")
  1220. " if there is no first line we default to the first line in the buffer so
  1221. " the fold start will always be included if the fold itself is included.
  1222. " If however the entire fold lies outside the range we need to remove it.
  1223. if afold.firstline > g:html_end_line
  1224. call remove(s:allfolds, index(s:allfolds, afold))
  1225. let removed = 1
  1226. endif
  1227. endif
  1228. if !removed
  1229. let afold.level -= leveladjust
  1230. if afold.level+1 > s:foldcolumn
  1231. let s:foldcolumn = afold.level+1
  1232. endif
  1233. endif
  1234. endfor
  1235. " if we've removed folds containing the conversion range from processing,
  1236. " getting foldtext as we go won't know to open the removed folds, so the
  1237. " foldtext would be wrong; open them now.
  1238. "
  1239. " Note that only when a start and an end line is specified will a fold
  1240. " containing the current range ever be removed.
  1241. while leveladjust > 0
  1242. exe g:html_start_line."foldopen"
  1243. let leveladjust -= 1
  1244. endwhile
  1245. endif
  1246. " Now loop over all lines in the original text to convert to html.
  1247. " Use html_start_line and html_end_line if they are set.
  1248. if exists("g:html_start_line")
  1249. let s:lnum = html_start_line
  1250. if s:lnum < 1 || s:lnum > line("$")
  1251. let s:lnum = 1
  1252. endif
  1253. else
  1254. let s:lnum = 1
  1255. endif
  1256. if exists("g:html_end_line")
  1257. let s:end = html_end_line
  1258. if s:end < s:lnum || s:end > line("$")
  1259. let s:end = line("$")
  1260. endif
  1261. else
  1262. let s:end = line("$")
  1263. endif
  1264. " stack to keep track of all the folds containing the current line
  1265. let s:foldstack = []
  1266. if !s:settings.no_progress
  1267. let s:pgb = s:ProgressBar("Processing lines:", s:end - s:lnum + 1, s:orgwin)
  1268. endif
  1269. if s:settings.number_lines
  1270. let s:margin = strlen(s:end) + 1
  1271. else
  1272. let s:margin = 0
  1273. endif
  1274. if has('folding') && !s:settings.ignore_folding
  1275. let s:foldfillchar = &fillchars[matchend(&fillchars, 'fold:')]
  1276. if s:foldfillchar == ''
  1277. let s:foldfillchar = '-'
  1278. endif
  1279. endif
  1280. let s:difffillchar = &fillchars[matchend(&fillchars, 'diff:')]
  1281. if s:difffillchar == ''
  1282. let s:difffillchar = '-'
  1283. endif
  1284. let s:foldId = 0
  1285. if !s:settings.expand_tabs
  1286. " If keeping tabs, add them to printable characters so we keep them when
  1287. " formatting text (strtrans() doesn't replace printable chars)
  1288. let s:old_isprint = &isprint
  1289. setlocal isprint+=9
  1290. endif
  1291. while s:lnum <= s:end
  1292. " If there are filler lines for diff mode, show these above the line.
  1293. let s:filler = diff_filler(s:lnum)
  1294. if s:filler > 0
  1295. let s:n = s:filler
  1296. while s:n > 0
  1297. let s:new = repeat(s:difffillchar, 3)
  1298. if s:n > 2 && s:n < s:filler && !s:settings.whole_filler
  1299. let s:new = s:new . " " . s:filler . " inserted lines "
  1300. let s:n = 2
  1301. endif
  1302. if !s:settings.no_pre
  1303. " HTML line wrapping is off--go ahead and fill to the margin
  1304. " TODO: what about when CSS wrapping is turned on?
  1305. let s:new = s:new . repeat(s:difffillchar, &columns - strlen(s:new) - s:margin)
  1306. else
  1307. let s:new = s:new . repeat(s:difffillchar, 3)
  1308. endif
  1309. let s:new = s:HtmlFormat_d(s:new, s:DIFF_D_ID, 0)
  1310. if s:settings.number_lines
  1311. " Indent if line numbering is on. Indent gets style of line number
  1312. " column.
  1313. let s:new = s:HtmlFormat_n(repeat(' ', s:margin), s:LINENR_ID, 0, 0) . s:new
  1314. endif
  1315. if s:settings.dynamic_folds && !s:settings.no_foldcolumn && s:foldcolumn > 0
  1316. " Indent for foldcolumn if there is one. Assume it's empty, there should
  1317. " not be a fold for deleted lines in diff mode.
  1318. let s:new = s:FoldColumn_fill() . s:new
  1319. endif
  1320. call add(s:lines, s:new.s:HtmlEndline)
  1321. let s:n = s:n - 1
  1322. endwhile
  1323. unlet s:n
  1324. endif
  1325. unlet s:filler
  1326. " Start the line with the line number.
  1327. if s:settings.number_lines
  1328. let s:numcol = repeat(' ', s:margin - 1 - strlen(s:lnum)) . s:lnum . ' '
  1329. endif
  1330. let s:new = ""
  1331. if has('folding') && !s:settings.ignore_folding && foldclosed(s:lnum) > -1 && !s:settings.dynamic_folds
  1332. "
  1333. " This is the beginning of a folded block (with no dynamic folding)
  1334. let s:new = foldtextresult(s:lnum)
  1335. if !s:settings.no_pre
  1336. " HTML line wrapping is off--go ahead and fill to the margin
  1337. let s:new = s:new . repeat(s:foldfillchar, &columns - strlen(s:new))
  1338. endif
  1339. " put numcol in a separate group for sake of unselectable text
  1340. 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)
  1341. " Skip to the end of the fold
  1342. let s:new_lnum = foldclosedend(s:lnum)
  1343. if !s:settings.no_progress
  1344. call s:pgb.incr(s:new_lnum - s:lnum)
  1345. endif
  1346. let s:lnum = s:new_lnum
  1347. else
  1348. "
  1349. " A line that is not folded, or doing dynamic folding.
  1350. "
  1351. let s:line = getline(s:lnum)
  1352. let s:len = strlen(s:line)
  1353. if s:settings.dynamic_folds
  1354. " First insert a closing for any open folds that end on this line
  1355. while !empty(s:foldstack) && get(s:foldstack,0).lastline == s:lnum-1
  1356. let s:new = s:new."</span></span>"
  1357. call remove(s:foldstack, 0)
  1358. endwhile
  1359. " Now insert an opening for any new folds that start on this line
  1360. let s:firstfold = 1
  1361. while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum
  1362. let s:foldId = s:foldId + 1
  1363. let s:new .= "<span id='"
  1364. let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "")
  1365. let s:new .= "fold".s:foldId.s:settings.id_suffix."' class='".s:allfolds[0].type."'>"
  1366. " Unless disabled, add a fold column for the opening line of a fold.
  1367. "
  1368. " Note that dynamic folds require using css so we just use css to take
  1369. " care of the leading spaces rather than using &nbsp; in the case of
  1370. " html_no_pre to make it easier
  1371. if !s:settings.no_foldcolumn
  1372. " add fold column that can open the new fold
  1373. if s:allfolds[0].level > 1 && s:firstfold
  1374. let s:new = s:new . s:FoldColumn_build('|', s:allfolds[0].level - 1, 0, "",
  1375. \ 'toggle-open FoldColumn','javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");')
  1376. endif
  1377. " add the filler spaces separately from the '+' char so that it can be
  1378. " shown/hidden separately during a hover unfold
  1379. let s:new = s:new . s:FoldColumn_build("+", 1, 0, "",
  1380. \ 'toggle-open FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
  1381. " If this is not the last fold we're opening on this line, we need
  1382. " to keep the filler spaces hidden if the fold is opened by mouse
  1383. " hover. If it is the last fold to open in the line, we shouldn't hide
  1384. " them, so don't apply the toggle-filler class.
  1385. let s:new = s:new . s:FoldColumn_build(" ", 1, s:foldcolumn - s:allfolds[0].level - 1, "",
  1386. \ 'toggle-open FoldColumn'. (get(s:allfolds, 1, {'firstline': 0}).firstline == s:lnum ?" toggle-filler" :""),
  1387. \ 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
  1388. " add fold column that can close the new fold
  1389. " only add extra blank space if we aren't opening another fold on the
  1390. " same line
  1391. if get(s:allfolds, 1, {'firstline': 0}).firstline != s:lnum
  1392. let s:extra_space = s:foldcolumn - s:allfolds[0].level
  1393. else
  1394. let s:extra_space = 0
  1395. endif
  1396. if s:firstfold
  1397. " the first fold in a line has '|' characters from folds opened in
  1398. " previous lines, before the '-' for this fold
  1399. let s:new .= s:FoldColumn_build('|', s:allfolds[0].level - 1, s:extra_space, '-',
  1400. \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
  1401. else
  1402. " any subsequent folds in the line only add a single '-'
  1403. let s:new = s:new . s:FoldColumn_build("-", 1, s:extra_space, "",
  1404. \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
  1405. endif
  1406. let s:firstfold = 0
  1407. endif
  1408. " Add fold text, moving the span ending to the next line so collapsing
  1409. " of folds works correctly.
  1410. " Put numcol in a separate group for sake of unselectable text.
  1411. 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), '</span>', s:HtmlEndline.'\n\0', '')
  1412. let s:new = s:new . "<span class='fulltext'>"
  1413. " open the fold now that we have the fold text to allow retrieval of
  1414. " fold text for subsequent folds
  1415. execute s:lnum."foldopen"
  1416. call insert(s:foldstack, remove(s:allfolds,0))
  1417. let s:foldstack[0].id = s:foldId
  1418. endwhile
  1419. " Unless disabled, add a fold column for other lines.
  1420. "
  1421. " Note that dynamic folds require using css so we just use css to take
  1422. " care of the leading spaces rather than using &nbsp; in the case of
  1423. " html_no_pre to make it easier
  1424. if !s:settings.no_foldcolumn
  1425. if empty(s:foldstack)
  1426. " add the empty foldcolumn for unfolded lines if there is a fold
  1427. " column at all
  1428. if s:foldcolumn > 0
  1429. let s:new = s:new . s:FoldColumn_fill()
  1430. endif
  1431. else
  1432. " add the fold column for folds not on the opening line
  1433. if get(s:foldstack, 0).firstline < s:lnum
  1434. let s:new = s:new . s:FoldColumn_build('|', s:foldstack[0].level, s:foldcolumn - s:foldstack[0].level, "",
  1435. \ 'FoldColumn', 'javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");')
  1436. endif
  1437. endif
  1438. endif
  1439. endif
  1440. " Now continue with the unfolded line text
  1441. if s:settings.number_lines
  1442. let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0, s:lnum)
  1443. elseif s:settings.line_ids
  1444. let s:new = s:new . s:HtmlFormat_n("", s:LINENR_ID, 0, s:lnum)
  1445. endif
  1446. " Get the diff attribute, if any.
  1447. let s:diffattr = diff_hlID(s:lnum, 1)
  1448. " initialize conceal info to act like not concealed, just in case
  1449. let s:concealinfo = [0, '']
  1450. " Loop over each character in the line
  1451. let s:col = 1
  1452. " most of the time we won't use the diff_id, initialize to zero
  1453. let s:diff_id = 0
  1454. while s:col <= s:len || (s:col == 1 && s:diffattr)
  1455. let s:startcol = s:col " The start column for processing text
  1456. if !s:settings.ignore_conceal && has('conceal')
  1457. let s:concealinfo = synconcealed(s:lnum, s:col)
  1458. endif
  1459. if !s:settings.ignore_conceal && s:concealinfo[0]
  1460. let s:col = s:col + 1
  1461. " Speed loop (it's small - that's the trick)
  1462. " Go along till we find a change in the match sequence number (ending
  1463. " the specific concealed region) or until there are no more concealed
  1464. " characters.
  1465. while s:col <= s:len && s:concealinfo == synconcealed(s:lnum, s:col) | let s:col = s:col + 1 | endwhile
  1466. elseif s:diffattr
  1467. let s:diff_id = diff_hlID(s:lnum, s:col)
  1468. let s:id = synID(s:lnum, s:col, 1)
  1469. let s:col = s:col + 1
  1470. " Speed loop (it's small - that's the trick)
  1471. " Go along till we find a change in hlID
  1472. while s:col <= s:len && s:id == synID(s:lnum, s:col, 1)
  1473. \ && s:diff_id == diff_hlID(s:lnum, s:col) |
  1474. \ let s:col = s:col + 1 |
  1475. \ endwhile
  1476. if s:len < &columns && !s:settings.no_pre
  1477. " Add spaces at the end of the raw text line to extend the changed
  1478. " line to the full width.
  1479. let s:line = s:line . repeat(' ', &columns - virtcol([s:lnum, s:len]) - s:margin)
  1480. let s:len = &columns
  1481. endif
  1482. else
  1483. let s:id = synID(s:lnum, s:col, 1)
  1484. let s:col = s:col + 1
  1485. " Speed loop (it's small - that's the trick)
  1486. " Go along till we find a change in synID
  1487. while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
  1488. endif
  1489. if s:settings.ignore_conceal || !s:concealinfo[0]
  1490. " Expand tabs if needed
  1491. let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol)
  1492. if s:settings.expand_tabs
  1493. let s:offset = 0
  1494. let s:idx = stridx(s:expandedtab, "\t")
  1495. let s:tablist = exists("+vts") ? split(&vts,',') : []
  1496. if empty(s:tablist)
  1497. let s:tablist = [ &ts ]
  1498. endif
  1499. let s:tabidx = 0
  1500. let s:tabwidth = 0
  1501. while s:idx >= 0
  1502. if s:startcol + s:idx == 1
  1503. let s:i = s:tablist[0]
  1504. else
  1505. " Get the character, which could be multiple bytes, which falls
  1506. " immediately before the found tab. Extract it by matching a
  1507. " character just prior to the column where the tab matches.
  1508. " We'll use this to get the byte index of the character
  1509. " immediately preceding the tab, so we can then look up the
  1510. " virtual column that character appears in, to determine how
  1511. " much of the current tabstop has been used up.
  1512. if s:idx == 0
  1513. " if the found tab is the first character in the text being
  1514. " processed, we need to get the character prior to the text,
  1515. " given by startcol.
  1516. let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:offset) . 'c')
  1517. else
  1518. " Otherwise, the byte index of the tab into s:expandedtab is
  1519. " given by s:idx.
  1520. let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c')
  1521. endif
  1522. let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)])
  1523. " find the tabstop interval to use for the tab we just found. Keep
  1524. " adding tabstops (which could be variable) until we would exceed
  1525. " the virtual screen position of the start of the found tab.
  1526. while s:vcol >= s:tabwidth + s:tablist[s:tabidx]
  1527. let s:tabwidth += s:tablist[s:tabidx]
  1528. if s:tabidx < len(s:tablist)-1
  1529. let s:tabidx = s:tabidx+1
  1530. endif
  1531. endwhile
  1532. let s:i = s:tablist[s:tabidx] - (s:vcol - s:tabwidth)
  1533. endif
  1534. " update offset to keep the index within the line corresponding to
  1535. " actual tab characters instead of replaced spaces; s:idx reflects
  1536. " replaced spaces in s:expandedtab, s:offset cancels out all but
  1537. " the tab character itself.
  1538. let s:offset -= s:i - 1
  1539. let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '')
  1540. let s:idx = stridx(s:expandedtab, "\t")
  1541. endwhile
  1542. end
  1543. " get the highlight group name to use
  1544. let s:id = synIDtrans(s:id)
  1545. else
  1546. " use Conceal highlighting for concealed text
  1547. let s:id = s:CONCEAL_ID
  1548. let s:expandedtab = s:concealinfo[1]
  1549. endif
  1550. " Output the text with the same synID, with class set to the highlight ID
  1551. " name, unless it has been concealed completely.
  1552. if strlen(s:expandedtab) > 0
  1553. let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id, s:diff_id, "", 0)
  1554. endif
  1555. endwhile
  1556. endif
  1557. call extend(s:lines, split(s:new.s:HtmlEndline, '\n', 1))
  1558. if !s:settings.no_progress && s:pgb.needs_redraw
  1559. redrawstatus
  1560. let s:pgb.needs_redraw = 0
  1561. endif
  1562. let s:lnum = s:lnum + 1
  1563. if !s:settings.no_progress
  1564. call s:pgb.incr()
  1565. endif
  1566. endwhile
  1567. if s:settings.dynamic_folds
  1568. " finish off any open folds
  1569. while !empty(s:foldstack)
  1570. let s:lines[-1].="</span></span>"
  1571. call remove(s:foldstack, 0)
  1572. endwhile
  1573. " add fold column to the style list if not already there
  1574. let s:id = s:FOLD_C_ID
  1575. if !has_key(s:stylelist, s:id)
  1576. let s:stylelist[s:id] = '.FoldColumn { ' . s:CSS1(s:id) . '}'
  1577. endif
  1578. endif
  1579. if s:settings.no_pre
  1580. if !s:settings.use_css
  1581. " Close off the font tag that encapsulates the whole <body>
  1582. call extend(s:lines, ["</font>", "</body>", "</html>"])
  1583. else
  1584. call extend(s:lines, ["</div>", "</body>", "</html>"])
  1585. endif
  1586. else
  1587. call extend(s:lines, ["</pre>", "</body>", "</html>"])
  1588. endif
  1589. exe s:newwin . "wincmd w"
  1590. call setline(1, s:lines)
  1591. unlet s:lines
  1592. " Mangle modelines so Vim doesn't try to use HTML text as a modeline if editing
  1593. " this file in the future; need to do this after generating all the text in case
  1594. " the modeline text has different highlight groups which all turn out to be
  1595. " stripped from the final output.
  1596. %s!\v(%(^|\s+)%([Vv]i%(m%([<=>]?\d+)?)?|ex)):!\1\&#0058;!ge
  1597. " The generated HTML is admittedly ugly and takes a LONG time to fold.
  1598. " Make sure the user doesn't do syntax folding when loading a generated file,
  1599. " using a modeline.
  1600. call append(line('$'), "<!-- vim: set foldmethod=manual : -->")
  1601. " Now, when we finally know which, we define the colors and styles
  1602. if s:settings.use_css
  1603. 1;/<style\>/+1
  1604. endif
  1605. " Normal/global attributes
  1606. if s:settings.use_css
  1607. if s:settings.no_pre
  1608. call append('.', "body { color: " . s:fgc . "; background-color: " . s:bgc . "; font-family: ". s:htmlfont ."; }")
  1609. +
  1610. else
  1611. call append('.', "pre { " . s:whitespace . "font-family: ". s:htmlfont ."; color: " . s:fgc . "; background-color: " . s:bgc . "; }")
  1612. +
  1613. yank
  1614. put
  1615. execute "normal! ^cwbody\e"
  1616. " body should not have the wrap formatting, only the pre section
  1617. if s:whitespace != ''
  1618. exec 's#'.s:whitespace
  1619. endif
  1620. endif
  1621. " fix browser inconsistencies (sometimes within the same browser) of different
  1622. " default font size for different elements
  1623. call append('.', '* { font-size: 1em; }')
  1624. +
  1625. " if we use any input elements for unselectable content, make sure they look
  1626. " like normal text
  1627. if !empty(s:settings.prevent_copy)
  1628. if s:settings.use_input_for_pc !=# "none"
  1629. call append('.', 'input { border: none; margin: 0; padding: 0; font-family: '.s:htmlfont.'; }')
  1630. +
  1631. " ch units for browsers which support them, em units for a somewhat
  1632. " reasonable fallback.
  1633. for w in range(1, 20, 1)
  1634. call append('.', [
  1635. \ "input[size='".w."'] { width: ".w."em; width: ".w."ch; }"
  1636. \ ])
  1637. +
  1638. endfor
  1639. endif
  1640. if s:settings.use_input_for_pc !=# 'all'
  1641. let s:unselectable_styles = []
  1642. if s:settings.prevent_copy =~# 'f'
  1643. call add(s:unselectable_styles, 'FoldColumn')
  1644. endif
  1645. if s:settings.prevent_copy =~# 'n'
  1646. call add(s:unselectable_styles, 'LineNr')
  1647. endif
  1648. if s:settings.prevent_copy =~# 't' && !s:settings.ignore_folding
  1649. call add(s:unselectable_styles, 'Folded')
  1650. endif
  1651. if s:settings.prevent_copy =~# 'd'
  1652. call add(s:unselectable_styles, 'DiffDelete')
  1653. endif
  1654. if s:settings.use_input_for_pc !=# 'none'
  1655. call append('.', [
  1656. \ '/* Note: IE does not support @supports conditionals, but also does not fully support',
  1657. \ ' "content:" with custom content, so we *want* the check to fail */',
  1658. \ '@supports ( content: attr(data-custom-content) ) {'
  1659. \ ])
  1660. +3
  1661. endif
  1662. " The line number column inside the foldtext is styled just like the fold
  1663. " text in Vim, but it should use the prevent_copy settings of line number
  1664. " rather than fold text. Apply the prevent_copy styles to foldtext
  1665. " specifically for line numbers, which always come after the fold column,
  1666. " or at the beginning of the line.
  1667. if s:settings.prevent_copy =~# 'n' && !s:settings.ignore_folding
  1668. call append('.', [
  1669. \ ' .FoldColumn + .Folded, .Folded:first-child { user-select: none; }',
  1670. \ ' .FoldColumn + [data-Folded-content]::before, [data-Folded-content]:first-child::before { content: attr(data-Folded-content); }',
  1671. \ ' .FoldColumn + [data-Folded-content]::before, [data-Folded-content]:first-child::before { padding-bottom: 1px; display: inline-block; /* match the 1-px padding of standard items with background */ }',
  1672. \ ' .FoldColumn + span[data-Folded-content]::before, [data-Folded-content]:first-child::before { cursor: default; }',
  1673. \ ])
  1674. +4
  1675. endif
  1676. for s:style_name in s:unselectable_styles
  1677. call append('.', [
  1678. \ ' .'.s:style_name.' { user-select: none; }',
  1679. \ ' [data-'.s:style_name.'-content]::before { content: attr(data-'.s:style_name.'-content); }',
  1680. \ ' [data-'.s:style_name.'-content]::before { padding-bottom: 1px; display: inline-block; /* match the 1-px padding of standard items with background */ }',
  1681. \ ' span[data-'.s:style_name.'-content]::before { cursor: default; }',
  1682. \ ])
  1683. +4
  1684. endfor
  1685. if s:settings.use_input_for_pc !=# 'none'
  1686. call append('.', [
  1687. \ ' input { display: none; }',
  1688. \ '}'
  1689. \ ])
  1690. +2
  1691. endif
  1692. unlet s:unselectable_styles
  1693. endif
  1694. " Fix mouse cursor shape for the fallback <input> method of uncopyable text
  1695. if s:settings.use_input_for_pc !=# 'none'
  1696. if s:settings.prevent_copy =~# 'f'
  1697. " Make the cursor show active fold columns as active areas, and empty fold
  1698. " columns as not interactive.
  1699. call append('.', ['input.FoldColumn { cursor: pointer; }',
  1700. \ 'input.FoldColumn[value="'.repeat(' ', s:foldcolumn).'"] { cursor: default; }'
  1701. \ ])
  1702. +2
  1703. if s:settings.use_input_for_pc !=# 'all'
  1704. call append('.', [
  1705. \ 'a[data-FoldColumn-content="'.repeat(' ', s:foldcolumn).'"] { cursor: default; }'
  1706. \ ])
  1707. +1
  1708. end
  1709. endif
  1710. " make line number column show as non-interactive if not selectable
  1711. if s:settings.prevent_copy =~# 'n'
  1712. call append('.', 'input.LineNr { cursor: default; }')
  1713. +
  1714. endif
  1715. " make fold text and line number column within fold text show as
  1716. " non-interactive if not selectable
  1717. if (s:settings.prevent_copy =~# 'n' || s:settings.prevent_copy =~# 't') && !s:settings.ignore_folding
  1718. call append('.', 'input.Folded { cursor: default; }')
  1719. +
  1720. endif
  1721. " make diff filler show as non-interactive if not selectable
  1722. if s:settings.prevent_copy =~# 'd'
  1723. call append('.', 'input.DiffDelete { cursor: default; }')
  1724. +
  1725. endif
  1726. endif
  1727. endif
  1728. else
  1729. " For Netscape 4, set <body> attributes too, though, strictly speaking, it's
  1730. " incorrect.
  1731. execute '%s:<body\([^>]*\):<body bgcolor="' . s:bgc . '" text="' . s:fgc . '"\1>\r<font face="'. s:htmlfont .'"'
  1732. endif
  1733. " Gather attributes for all other classes. Do diff first so that normal
  1734. " highlight groups are inserted before it.
  1735. if s:settings.use_css
  1736. if s:diff_mode
  1737. call append('.', filter(map(keys(s:diffstylelist), "s:diffstylelist[v:val]"), 'v:val != ""'))
  1738. endif
  1739. if !empty(s:stylelist)
  1740. call append('.', filter(map(keys(s:stylelist), "s:stylelist[v:val]"), 'v:val != ""'))
  1741. endif
  1742. endif
  1743. " Add hyperlinks
  1744. " TODO: add option to not do this? Maybe just make the color the same as the
  1745. " text highlight group normally is?
  1746. %s+\(https\=://\S\{-}\)\(\([.,;:}]\=\(\s\|$\)\)\|[\\"'<>]\|&gt;\|&lt;\|&quot;\)+<a href="\1">\1</a>\2+ge
  1747. " The DTD
  1748. if s:settings.use_xhtml
  1749. 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\">"
  1750. elseif s:html5
  1751. exe "normal! gg0i<!DOCTYPE html>\n"
  1752. else
  1753. exe "normal! gg0i<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n"
  1754. endif
  1755. if s:settings.use_xhtml
  1756. exe "normal! gg/<html/e\na xmlns=\"http://www.w3.org/1999/xhtml\"\e"
  1757. endif
  1758. " Cleanup
  1759. %s:\s\+$::e
  1760. " Restore old settings (new window first)
  1761. "
  1762. " Don't bother restoring foldmethod in case it was syntax because the markup is
  1763. " so weirdly formatted it can take a LONG time.
  1764. let &l:foldenable = s:old_fen
  1765. let &report = s:old_report
  1766. let &title = s:old_title
  1767. let &icon = s:old_icon
  1768. let &paste = s:old_paste
  1769. let &magic = s:old_magic
  1770. let @/ = s:old_search
  1771. let &more = s:old_more
  1772. " switch to original window to restore those settings
  1773. exe s:orgwin . "wincmd w"
  1774. if !s:settings.expand_tabs
  1775. let &l:isprint = s:old_isprint
  1776. endif
  1777. let &l:stl = s:origwin_stl
  1778. let &l:et = s:old_et
  1779. let &l:scrollbind = s:old_bind
  1780. " and back to the new window again to end there
  1781. exe s:newwin . "wincmd w"
  1782. let &l:stl = s:newwin_stl
  1783. exec 'resize' s:old_winheight
  1784. let &l:winfixheight = s:old_winfixheight
  1785. let &ls=s:ls
  1786. let &eventignore=s:ei_sav
  1787. " Save a little bit of memory (worth doing?)
  1788. unlet s:htmlfont s:whitespace
  1789. unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search
  1790. unlet s:old_magic s:old_more s:old_fen s:old_winheight
  1791. unlet! s:old_isprint
  1792. unlet s:whatterm s:stylelist s:diffstylelist s:lnum s:end s:margin s:fgc s:bgc s:old_winfixheight
  1793. unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:concealinfo s:diff_mode
  1794. unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset s:ls s:ei_sav s:origwin_stl
  1795. unlet! s:newwin_stl s:current_syntax
  1796. if !v:profiling
  1797. delfunc s:HtmlColor
  1798. delfunc s:HtmlFormat
  1799. delfunc s:CSS1
  1800. delfunc s:BuildStyleWrapper
  1801. if !s:settings.use_css
  1802. delfunc s:HtmlOpening
  1803. delfunc s:HtmlClosing
  1804. endif
  1805. if s:settings.dynamic_folds
  1806. delfunc s:FoldCompare
  1807. endif
  1808. if !s:settings.no_progress
  1809. delfunc s:ProgressBar
  1810. delfunc s:progressbar.paint
  1811. delfunc s:progressbar.incr
  1812. unlet s:pgb s:progressbar
  1813. endif
  1814. endif
  1815. unlet! s:new_lnum s:diffattr s:difffillchar s:foldfillchar s:HtmlSpace
  1816. unlet! s:LeadingSpace s:HtmlEndline s:firstfold s:numcol s:foldcolumn
  1817. unlet s:foldstack s:allfolds s:foldId s:settings
  1818. let &cpo = s:cpo_sav
  1819. unlet! s:cpo_sav
  1820. " Make sure any patches will probably use consistent indent
  1821. " vim: ts=8 sw=2 sts=2 noet