11" Vim autoload file for the tohtml plugin.
22" Maintainer: Ben Fritz <[email protected] >3- " Last Change: 2018 Nov 11
3+ " Last Change: 2019 Aug 16
44"
55" Additional contributors:
66"
@@ -364,15 +364,17 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
364364 let body_line = ' '
365365
366366 let html = []
367+ let s: html5 = 0
367368 if s: settings .use_xhtml
368369 call add (html, xml_line)
369370 endif
370371 if s: settings .use_xhtml
371372 call add (html, " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \" http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\" >" )
372373 call add (html, ' <html xmlns="http://www.w3.org/1999/xhtml">' )
373374 elseif s: settings .use_css && ! s: settings .no_pre
374- call add (html, " <!DOCTYPE HTML PUBLIC \" -//W3C//DTD HTML 4.01//EN \" \" http://www.w3.org/TR/html4/strict.dtd \" >" )
375+ call add (html, " <!DOCTYPE html >" )
375376 call add (html, ' <html>' )
377+ let s: html5 = 1
376378 else
377379 call add (html, ' <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"' )
378380 call add (html, ' "http://www.w3.org/TR/html4/loose.dtd">' )
@@ -383,7 +385,11 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
383385 " include encoding as close to the top as possible, but only if not already
384386 " contained in XML information
385387 if s: settings .encoding != " " && ! s: settings .use_xhtml
386- call add (html, " <meta http-equiv=\" content-type\" content=\" text/html; charset=" . s: settings .encoding . ' "' . tag_close)
388+ if s: html5
389+ call add (html, ' <meta charset="' . s: settings .encoding . ' "' . tag_close)
390+ else
391+ call add (html, " <meta http-equiv=\" content-type\" content=\" text/html; charset=" . s: settings .encoding . ' "' . tag_close)
392+ endif
387393 endif
388394
389395 call add (html, ' <title>diff</title>' )
@@ -392,6 +398,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
392398 call add (html, ' <meta name="settings" content="' .
393399 \ join (filter (keys (s: settings ),' s:settings[v:val]' ),' ,' ).
394400 \ ' ,prevent_copy=' .s: settings .prevent_copy.
401+ \ ' ,use_input_for_pc=' .s: settings .use_input_for_pc.
395402 \ ' "' .tag_close)
396403 call add (html, ' <meta name="colorscheme" content="' .
397404 \ (exists (' g:colors_name' )
@@ -400,16 +407,8 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
400407
401408 call add (html, ' </head>' )
402409 let body_line_num = len (html)
403- if ! empty (s: settings .prevent_copy)
404- call add (html, " <body onload='FixCharWidth();" .(s: settings .line_ids ? " JumpToLine();" : " " )." '>" )
405- call add (html, " <!-- hidden divs used by javascript to get the width of a char -->" )
406- call add (html, " <div id='oneCharWidth'>0</div>" )
407- call add (html, " <div id='oneInputWidth'><input size='1' value='0'" .tag_close." </div>" )
408- call add (html, " <div id='oneEmWidth' style='width: 1em;'></div>" )
409- else
410- call add (html, ' <body' .(s: settings .line_ids ? ' onload="JumpToLine();"' : ' ' ).' >' )
411- endif
412- call add (html, " <table border='1' width='100%' id='vimCodeElement" .s: settings .id_suffix." '>" )
410+ call add (html, ' <body' .(s: settings .line_ids ? ' onload="JumpToLine();"' : ' ' ).' >' )
411+ call add (html, " <table " .(s: settings .use_css? " " : " border='1' width='100%' " )." id='vimCodeElement" .s: settings .id_suffix." '>" )
413412
414413 call add (html, ' <tr>' )
415414 for buf in a: win_list
@@ -443,7 +442,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
443442 " Grab the style information. Some of this will be duplicated so only insert
444443 " it if it's not already there. {{{
445444 1
446- let style_start = search (' ^<style type="text/css">' )
445+ let style_start = search (' ^<style\( type="text/css"\)\? >' )
447446 1
448447 let style_end = search (' ^</style>' )
449448 if style_start > 0 && style_end > 0
@@ -481,7 +480,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
481480 " TODO: restore using grabbed lines if undolevel is 1?
482481 normal ! 2 u
483482 if s: settings .use_css
484- call add (html, ' <td valign="top" ><div>' )
483+ call add (html, ' <td><div>' )
485484 elseif s: settings .use_xhtml
486485 call add (html, ' <td nowrap="nowrap" valign="top"><div>' )
487486 else
@@ -515,7 +514,13 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
515514 let name = substitute (name, ' \d*\.x\?html$' , ' ' , ' ' ) . i . ' .' . fnamemodify (copy (name), " :t:e" )
516515 let i += 1
517516 endwhile
517+
518+ let s: ei_sav = &eventignore
519+ set eventignore += FileType
518520 exe " topleft new " . name
521+ let &eventignore = s: ei_sav
522+ unlet s: ei_sav
523+
519524 setlocal modifiable
520525
521526 " just in case some user autocmd creates content in the new buffer, make sure
@@ -544,7 +549,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
544549 " add required javascript in reverse order so we can just call append again
545550 " and again without adjusting {{{
546551
547- let s: uses_script = s: settings .dynamic_folds || s: settings .line_ids || ! empty ( s: settings .prevent_copy)
552+ let s: uses_script = s: settings .dynamic_folds || s: settings .line_ids
548553
549554 " insert script closing tag if needed
550555 if s: uses_script
@@ -555,31 +560,6 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
555560 \ ])
556561 endif
557562
558- " insert script which corrects the size of small input elements in
559- " prevent_copy mode. See 2html.vim for details on why this is needed and how
560- " it works.
561- if ! empty (s: settings .prevent_copy)
562- call append (style_start, [
563- \ ' ' ,
564- \ ' /* simulate a "ch" unit by asking the browser how big a zero character is */' ,
565- \ ' function FixCharWidth() {' ,
566- \ ' /* get the hidden element which gives the width of a single character */' ,
567- \ ' var goodWidth = document.getElementById("oneCharWidth").clientWidth;' ,
568- \ ' /* get all input elements, we'' ll filter on class later */' ,
569- \ ' var inputTags = document.getElementsByTagName("input");' ,
570- \ ' var ratio = 5;' ,
571- \ ' var inputWidth = document.getElementById("oneInputWidth").clientWidth;' ,
572- \ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;' ,
573- \ ' if (inputWidth > goodWidth) {' ,
574- \ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {' ,
575- \ ' ratio += 5;' ,
576- \ ' }' ,
577- \ ' document.getElementById("vimCodeElement' .s: settings .id_suffix.' ").className = "em"+ratio;' ,
578- \ ' }' ,
579- \ ' }'
580- \ ])
581- endif
582-
583563 " insert javascript to get IDs from line numbers, and to open a fold before
584564 " jumping to any lines contained therein
585565 if s: settings .line_ids
@@ -659,10 +639,9 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
659639 endif
660640
661641 if s: uses_script
662- " insert script tag; javascript is always needed for the line number
663- " normalization for URL hashes
642+ " insert script tag if needed
664643 call append (style_start, [
665- \ " <script type='text/javascript'>" ,
644+ \ " <script" . ( s: html5 ? " " : " type='text/javascript'" ) . " >" ,
666645 \ s: settings .use_xhtml ? ' //<![CDATA[' : " <!--" ])
667646 endif
668647
@@ -673,11 +652,13 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
673652 " is pretty useless for really long lines. {{{
674653 if s: settings .use_css
675654 call append (style_start,
676- \ [' <style type="text/css">' ]+
655+ \ [' <style' . ( s: html5 ? ' ' : ' type="text/css"' ) . ' >' ]+
677656 \ style+
678657 \ [ s: settings .use_xhtml ? ' ' : ' <!--' ,
679658 \ ' table { table-layout: fixed; }' ,
680659 \ ' html, body, table, tbody { width: 100%; margin: 0; padding: 0; }' ,
660+ \ ' table, td, th { border: 1px solid; }' ,
661+ \ ' td { vertical-align: top; }' ,
681662 \ ' th, td { width: ' .printf (" %.1f" ,100.0 /len (a: win_list )).' %; }' ,
682663 \ ' td div { overflow: auto; }' ,
683664 \ s: settings .use_xhtml ? ' ' : ' -->' ,
@@ -720,21 +701,22 @@ func! tohtml#GetUserSettings() "{{{
720701 endif
721702
722703 " get current option settings with appropriate defaults {{{
723- call tohtml#GetOption (user_settings, ' no_progress' , ! has (" statusline" ) )
724- call tohtml#GetOption (user_settings, ' diff_one_file' , 0 )
725- call tohtml#GetOption (user_settings, ' number_lines' , &number )
726- call tohtml#GetOption (user_settings, ' pre_wrap' , &wrap )
727- call tohtml#GetOption (user_settings, ' use_css' , 1 )
728- call tohtml#GetOption (user_settings, ' ignore_conceal' , 0 )
729- call tohtml#GetOption (user_settings, ' ignore_folding' , 0 )
730- call tohtml#GetOption (user_settings, ' dynamic_folds' , 0 )
731- call tohtml#GetOption (user_settings, ' no_foldcolumn' , user_settings.ignore_folding)
732- call tohtml#GetOption (user_settings, ' hover_unfold' , 0 )
733- call tohtml#GetOption (user_settings, ' no_pre' , 0 )
734- call tohtml#GetOption (user_settings, ' no_invalid' , 0 )
735- call tohtml#GetOption (user_settings, ' whole_filler' , 0 )
736- call tohtml#GetOption (user_settings, ' use_xhtml' , 0 )
737- call tohtml#GetOption (user_settings, ' line_ids' , user_settings.number_lines )
704+ call tohtml#GetOption (user_settings, ' no_progress' , ! has (" statusline" ) )
705+ call tohtml#GetOption (user_settings, ' diff_one_file' , 0 )
706+ call tohtml#GetOption (user_settings, ' number_lines' , &number )
707+ call tohtml#GetOption (user_settings, ' pre_wrap' , &wrap )
708+ call tohtml#GetOption (user_settings, ' use_css' , 1 )
709+ call tohtml#GetOption (user_settings, ' ignore_conceal' , 0 )
710+ call tohtml#GetOption (user_settings, ' ignore_folding' , 0 )
711+ call tohtml#GetOption (user_settings, ' dynamic_folds' , 0 )
712+ call tohtml#GetOption (user_settings, ' no_foldcolumn' , user_settings.ignore_folding)
713+ call tohtml#GetOption (user_settings, ' hover_unfold' , 0 )
714+ call tohtml#GetOption (user_settings, ' no_pre' , 0 )
715+ call tohtml#GetOption (user_settings, ' no_invalid' , 0 )
716+ call tohtml#GetOption (user_settings, ' whole_filler' , 0 )
717+ call tohtml#GetOption (user_settings, ' use_xhtml' , 0 )
718+ call tohtml#GetOption (user_settings, ' line_ids' , user_settings.number_lines )
719+ call tohtml#GetOption (user_settings, ' use_input_for_pc' , ' fallback' )
738720 " }}}
739721
740722 " override those settings that need it {{{
@@ -868,6 +850,16 @@ func! tohtml#GetUserSettings() "{{{
868850 let user_settings.no_invalid = 0
869851 endif
870852
853+ " enforce valid values for use_input_for_pc
854+ if user_settings.use_input_for_pc !~# ' fallback\|none\|all'
855+ let user_settings.use_input_for_pc = ' fallback'
856+ echohl WarningMsg
857+ echomsg ' 2html: "' . g: html_use_input_for_pc . ' " is not valid for g:html_use_input_for_pc'
858+ echomsg ' 2html: defaulting to "' . user_settings.use_input_for_pc . ' "'
859+ echohl None
860+ sleep 3
861+ endif
862+
871863 if exists (' g:html_id_expr' )
872864 let user_settings.id_suffix = eval (g: html_id_expr )
873865 if user_settings.id_suffix !~ ' ^[-_:.A-Za-z0-9]*$'
0 commit comments