Skip to content

Commit 86cfb39

Browse files
runtime(tohtml): Update TOhtml to version 9.0v2 (#13050)
Modified behavior: - Change default value of g:html_use_input_for_pc from "fallback" to "none". This means with default settings, only the standards-based method to make special text unselectable is used. The old method relying on unspecified browser behavior for <input> tags is now only used if a user specifically enables it. - Officially deprecate g:use_xhtml option (in favor of g:html_use_xhtml) by issuing a warning message when used. Bugfixes: - Fix issue #8547: LineNr and other special highlight groups did not get proper style rules defined when using "hi link". - Fix that diff filler was not properly added for deleted lines at the end of a buffer. Other: - Refactored function definitions from long lists of strings to use :let-heredoc variable assignment instead. - Corrected deprecated "." string concatenation operator to ".." operator in more places. Signed-off-by: Christian Brabandt <[email protected]>
1 parent 1bd2cb1 commit 86cfb39

4 files changed

Lines changed: 428 additions & 335 deletions

File tree

runtime/autoload/tohtml.vim

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim autoload file for the tohtml plugin.
22
" Maintainer: Ben Fritz <[email protected]>
3-
" Last Change: 2023 Jan 01
3+
" Last Change: 2023 Sep 03
44
"
55
" Additional contributors:
66
"
@@ -307,7 +307,7 @@ func! tohtml#Convert2HTML(line1, line2) "{{{
307307
let g:html_diff_win_num = 0
308308
for window in win_list
309309
" switch to the next buffer to convert
310-
exe ":" . bufwinnr(window) . "wincmd w"
310+
exe ":" .. bufwinnr(window) .. "wincmd w"
311311

312312
" figure out whether current charset and encoding will work, if not
313313
" default to UTF-8
@@ -355,7 +355,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
355355
if !s:settings.no_doc
356356
if s:settings.use_xhtml
357357
if s:settings.encoding != ""
358-
let xml_line = "<?xml version=\"1.0\" encoding=\"" . s:settings.encoding . "\"?>"
358+
let xml_line = "<?xml version=\"1.0\" encoding=\"" .. s:settings.encoding .. "\"?>"
359359
else
360360
let xml_line = "<?xml version=\"1.0\"?>"
361361
endif
@@ -387,34 +387,34 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
387387
" contained in XML information
388388
if s:settings.encoding != "" && !s:settings.use_xhtml
389389
if s:html5
390-
call add(html, '<meta charset="' . s:settings.encoding . '"' . tag_close)
390+
call add(html, '<meta charset="' .. s:settings.encoding .. '"' .. tag_close)
391391
else
392-
call add(html, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:settings.encoding . '"' . tag_close)
392+
call add(html, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" .. s:settings.encoding .. '"' .. tag_close)
393393
endif
394394
endif
395395

396396
call add(html, '<title>diff</title>')
397-
call add(html, '<meta name="Generator" content="Vim/'.v:version/100.'.'.v:version%100.'"'.tag_close)
398-
call add(html, '<meta name="plugin-version" content="'.g:loaded_2html_plugin.'"'.tag_close)
397+
call add(html, '<meta name="Generator" content="Vim/'..v:version/100..'.'..v:version%100..'"'..tag_close)
398+
call add(html, '<meta name="plugin-version" content="'..g:loaded_2html_plugin..'"'..tag_close)
399399
call add(html, '<meta name="settings" content="'.
400400
\ join(filter(keys(s:settings),'s:settings[v:val]'),',').
401-
\ ',prevent_copy='.s:settings.prevent_copy.
402-
\ ',use_input_for_pc='.s:settings.use_input_for_pc.
403-
\ '"'.tag_close)
401+
\ ',prevent_copy='..s:settings.prevent_copy.
402+
\ ',use_input_for_pc='..s:settings.use_input_for_pc.
403+
\ '"'..tag_close)
404404
call add(html, '<meta name="colorscheme" content="'.
405405
\ (exists('g:colors_name')
406406
\ ? g:colors_name
407-
\ : 'none'). '"'.tag_close)
407+
\ : 'none').. '"'..tag_close)
408408

409409
call add(html, '</head>')
410410
let body_line_num = len(html)
411-
call add(html, '<body'.(s:settings.line_ids ? ' onload="JumpToLine();"' : '').'>')
411+
call add(html, '<body'..(s:settings.line_ids ? ' onload="JumpToLine();"' : '')..'>')
412412
endif
413-
call add(html, "<table ".(s:settings.use_css? "" : "border='1' width='100%' ")."id='vimCodeElement".s:settings.id_suffix."'>")
413+
call add(html, "<table "..(s:settings.use_css? "" : "border='1' width='100%' ").."id='vimCodeElement"..s:settings.id_suffix.."'>")
414414

415415
call add(html, '<tr>')
416416
for buf in a:win_list
417-
call add(html, '<th>'.bufname(buf).'</th>')
417+
call add(html, '<th>'..bufname(buf)..'</th>')
418418
endfor
419419
call add(html, '</tr><tr>')
420420

@@ -423,7 +423,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
423423

424424
for buf in a:buf_list
425425
let temp = []
426-
exe bufwinnr(buf) . 'wincmd w'
426+
exe bufwinnr(buf) .. 'wincmd w'
427427

428428
" If text is folded because of user foldmethod settings, etc. we don't want
429429
" to act on everything in a fold by mistake.
@@ -526,16 +526,16 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
526526
endif
527527

528528
let i = 1
529-
let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html")
529+
let name = "Diff" .. (s:settings.use_xhtml ? ".xhtml" : ".html")
530530
" Find an unused file name if current file name is already in use
531531
while filereadable(name)
532-
let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e")
532+
let name = substitute(name, '\d*\.x\?html$', '', '') .. i .. '.' .. fnamemodify(copy(name), ":t:e")
533533
let i += 1
534534
endwhile
535535

536536
let s:ei_sav = &eventignore
537537
set eventignore+=FileType
538-
exe "topleft new " . name
538+
exe "topleft new " .. name
539539
let &eventignore=s:ei_sav
540540
unlet s:ei_sav
541541

@@ -601,7 +601,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
601601
\ "",
602602
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
603603
\ " var node = lineElem;",
604-
\ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
604+
\ " while (node && node.id != 'vimCodeElement"..s:settings.id_suffix.."')",
605605
\ " {",
606606
\ " if (node.className == 'closed-fold')",
607607
\ " {",
@@ -640,7 +640,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
640640
call append(style_start, [
641641
\ " function toggleFold(objID)",
642642
\ " {",
643-
\ " for (win_num = 1; win_num <= ".len(a:buf_list)."; win_num++)",
643+
\ " for (win_num = 1; win_num <= "..len(a:buf_list).."; win_num++)",
644644
\ " {",
645645
\ " var fold;",
646646
\ ' fold = document.getElementById("win"+win_num+objID);',
@@ -660,7 +660,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
660660
if s:uses_script
661661
" insert script tag if needed
662662
call append(style_start, [
663-
\ "<script" . (s:html5 ? "" : " type='text/javascript'") . ">",
663+
\ "<script" .. (s:html5 ? "" : " type='text/javascript'") .. ">",
664664
\ s:settings.use_xhtml ? '//<![CDATA[' : "<!--"])
665665
endif
666666

@@ -671,14 +671,14 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
671671
" is pretty useless for really long lines. {{{
672672
if s:settings.use_css
673673
call append(style_start,
674-
\ ['<style' . (s:html5 ? '' : 'type="text/css"') . '>']+
674+
\ ['<style' .. (s:html5 ? '' : 'type="text/css"') .. '>']+
675675
\ style+
676676
\ [ s:settings.use_xhtml ? '' : '<!--',
677677
\ 'table { table-layout: fixed; }',
678678
\ 'html, body, table, tbody { width: 100%; margin: 0; padding: 0; }',
679679
\ 'table, td, th { border: 1px solid; }',
680680
\ 'td { vertical-align: top; }',
681-
\ 'th, td { width: '.printf("%.1f",100.0/len(a:win_list)).'%; }',
681+
\ 'th, td { width: '..printf("%.1f",100.0/len(a:win_list))..'%; }',
682682
\ 'td div { overflow: auto; }',
683683
\ s:settings.use_xhtml ? '' : '-->',
684684
\ '</style>'
@@ -694,7 +694,7 @@ endfunc "}}}
694694
" Gets a single user option and sets it in the passed-in Dict, or gives it the
695695
" default value if the option doesn't actually exist.
696696
func! tohtml#GetOption(settings, option, default) "{{{
697-
if exists('g:html_'.a:option)
697+
if exists('g:html_'..a:option)
698698
let a:settings[a:option] = g:html_{a:option}
699699
else
700700
let a:settings[a:option] = a:default
@@ -713,10 +713,11 @@ func! tohtml#GetUserSettings() "{{{
713713
let user_settings = {}
714714

715715
" Define the correct option if the old option name exists and we haven't
716-
" already defined the correct one. Maybe I'll put out a warning message about
717-
" this sometime and remove the old option entirely at some even later time,
718-
" but for now just silently accept the old option.
716+
" already defined the correct one.
719717
if exists('g:use_xhtml') && !exists("g:html_use_xhtml")
718+
echohl WarningMsg
719+
echomsg "Warning: g:use_xhtml is deprecated, use g:html_use_xhtml"
720+
echohl None
720721
let g:html_use_xhtml = g:use_xhtml
721722
endif
722723

@@ -739,7 +740,7 @@ func! tohtml#GetUserSettings() "{{{
739740
call tohtml#GetOption(user_settings, 'whole_filler', 0 )
740741
call tohtml#GetOption(user_settings, 'use_xhtml', 0 )
741742
call tohtml#GetOption(user_settings, 'line_ids', user_settings.number_lines )
742-
call tohtml#GetOption(user_settings, 'use_input_for_pc', 'fallback')
743+
call tohtml#GetOption(user_settings, 'use_input_for_pc', 'none')
743744
" }}}
744745

745746
" override those settings that need it {{{
@@ -854,16 +855,16 @@ func! tohtml#GetUserSettings() "{{{
854855
if user_settings.use_css
855856
if exists("g:html_prevent_copy")
856857
if user_settings.dynamic_folds && !user_settings.no_foldcolumn && g:html_prevent_copy =~# 'f'
857-
let user_settings.prevent_copy .= 'f'
858+
let user_settings.prevent_copy ..= 'f'
858859
endif
859860
if user_settings.number_lines && g:html_prevent_copy =~# 'n'
860-
let user_settings.prevent_copy .= 'n'
861+
let user_settings.prevent_copy ..= 'n'
861862
endif
862863
if &diff && g:html_prevent_copy =~# 'd'
863-
let user_settings.prevent_copy .= 'd'
864+
let user_settings.prevent_copy ..= 'd'
864865
endif
865866
if !user_settings.ignore_folding && g:html_prevent_copy =~# 't'
866-
let user_settings.prevent_copy .= 't'
867+
let user_settings.prevent_copy ..= 't'
867868
endif
868869
else
869870
let user_settings.prevent_copy = ""
@@ -875,10 +876,10 @@ func! tohtml#GetUserSettings() "{{{
875876

876877
" enforce valid values for use_input_for_pc
877878
if user_settings.use_input_for_pc !~# 'fallback\|none\|all'
878-
let user_settings.use_input_for_pc = 'fallback'
879+
let user_settings.use_input_for_pc = 'none'
879880
echohl WarningMsg
880-
echomsg '2html: "' . g:html_use_input_for_pc . '" is not valid for g:html_use_input_for_pc'
881-
echomsg '2html: defaulting to "' . user_settings.use_input_for_pc . '"'
881+
echomsg '2html: "' .. g:html_use_input_for_pc .. '" is not valid for g:html_use_input_for_pc'
882+
echomsg '2html: defaulting to "' .. user_settings.use_input_for_pc .. '"'
882883
echohl None
883884
sleep 3
884885
endif

runtime/doc/syntax.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ The method used to prevent copying in the generated page depends on the value
596596
of |g:html_use_input_for_pc|.
597597

598598
*g:html_use_input_for_pc*
599-
Default: "fallback"
599+
Default: "none"
600600
If |g:html_prevent_copy| is non-empty, then:
601601

602602
When "all", read-only <input> elements are used in place of normal text for

runtime/plugin/tohtml.vim

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
11
" Vim plugin for converting a syntax highlighted file to HTML.
22
" Maintainer: Ben Fritz <[email protected]>
3-
" Last Change: 2023 Jan 01
3+
" Last Change: 2023 Sep 07
44
"
55
" The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and
66
" $VIMRUNTIME/syntax/2html.vim
77
"
88
if exists('g:loaded_2html_plugin')
99
finish
1010
endif
11-
let g:loaded_2html_plugin = 'vim9.0_v1'
11+
let g:loaded_2html_plugin = 'vim9.0_v2'
1212

1313
"
1414
" Changelog: {{{
15-
" 9.0_v1 (this version): - Implement g:html_no_doc and g:html_no_modeline
15+
" 9.0_v2 (this version): - Warn if using deprecated g:use_xhtml option
16+
" - Change default g:html_use_input_for_pc to "none"
17+
" instead of "fallback". All modern browsers support
18+
" the "user-select: none" and "content:" CSS
19+
" properties so the older method relying on extra
20+
" markup and unspecified browser/app clipboard
21+
" handling is only needed in rare special cases.
22+
" - Fix SourceForge issue #33: generate diff filler
23+
" correctly when new lines have been added to or
24+
" removed from end of buffer.
25+
" - Fix SourceForge issue #32/Vim Github issue #8547:
26+
" use translated highlight ID for styling the
27+
" special-use group names (e.g. LineNr) used
28+
" directly by name in the 2html processing.
29+
" - Fix SourceForge issue #26, refactoring to use
30+
" :let-heredoc style string assignment and
31+
" additional fixes for ".." vs. "." style string
32+
" concatenation. Requires Vim v8.1.1354 or higher.
33+
" 9.0_v1 (Vim 9.0.1275): - Implement g:html_no_doc and g:html_no_modeline
1634
" for diff mode. Add tests.
1735
" (Vim 9.0.1122): NOTE: no version string update for this version!
1836
" - Bugfix for variable name in g:html_no_doc
@@ -21,7 +39,8 @@ let g:loaded_2html_plugin = 'vim9.0_v1'
2139
" and g:html_no_modeline (partially included in Vim
2240
" runtime prior to version string update).
2341
" - Updates for new Vim9 string append style (i.e. use
24-
" ".." instead of ".")
42+
" ".." instead of "."). Requires Vim version
43+
" 8.1.1114 or higher.
2544
"
2645
" 8.1 updates: {{{
2746
" 8.1_v2 (Vim 8.1.2312): - Fix SourceForge issue #19: fix calculation of tab

0 commit comments

Comments
 (0)