Skip to content

Commit 564fb60

Browse files
committed
Updated runtime files. New version of TOhtml plugin.
1 parent c8da850 commit 564fb60

File tree

6 files changed

+177
-105
lines changed

6 files changed

+177
-105
lines changed

runtime/autoload/tohtml.vim

Lines changed: 24 additions & 9 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: 2013 May 31
3+
" Last Change: 2013 Jun 19
44
"
55
" Additional contributors:
66
"
@@ -401,15 +401,15 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
401401
call add(html, '</head>')
402402
let body_line_num = len(html)
403403
if !empty(s:settings.prevent_copy)
404-
call add(html, "<body onload='FixCharWidth(); JumpToLine();'>")
404+
call add(html, "<body onload='FixCharWidth();".(s:settings.line_ids ? " JumpToLine();" : "")."'>")
405405
call add(html, "<!-- hidden divs used by javascript to get the width of a char -->")
406406
call add(html, "<div id='oneCharWidth'>0</div>")
407407
call add(html, "<div id='oneInputWidth'><input size='1' value='0'".tag_close."</div>")
408408
call add(html, "<div id='oneEmWidth' style='width: 1em;'></div>")
409409
else
410-
call add(html, '<body onload="JumpToLine();">')
410+
call add(html, '<body'.(s:settings.line_ids ? ' onload="JumpToLine();"' : '').'>')
411411
endif
412-
call add(html, "<table border='1' width='100%' id='vimCodeElement'>")
412+
call add(html, "<table border='1' width='100%' id='vimCodeElement".s:settings.id_suffix."'>")
413413

414414
call add(html, '<tr>')
415415
for buf in a:win_list
@@ -475,7 +475,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
475475
let temp = getline(1,'$')
476476
" clean out id on the main content container because we already set it on
477477
" the table
478-
let temp[0] = substitute(temp[0], " id='vimCodeElement'", "", "")
478+
let temp[0] = substitute(temp[0], " id='vimCodeElement[^']*'", "", "")
479479
" undo deletion of start and end part
480480
" so we can later save the file as valid html
481481
" TODO: restore using grabbed lines if undolevel is 1?
@@ -568,9 +568,9 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
568568
\ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;',
569569
\ ' if (inputWidth > goodWidth) {',
570570
\ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {',
571-
\ ' ratio += 5;',
572-
\ ' }',
573-
\ ' document.getElementById("vimCodeElement").className = "em"+ratio;',
571+
\ ' ratio += 5;',
572+
\ ' }',
573+
\ ' document.getElementById("vimCodeElement'.s:settings.id_suffix.'").className = "em"+ratio;',
574574
\ ' }',
575575
\ '}'
576576
\ ])
@@ -596,7 +596,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
596596
\ "",
597597
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
598598
\ " var node = lineElem;",
599-
\ " while (node && node.id != 'vimCodeElement')",
599+
\ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
600600
\ " {",
601601
\ " if (node.className == 'closed-fold')",
602602
\ " {",
@@ -722,6 +722,7 @@ func! tohtml#GetUserSettings() "{{{
722722
call tohtml#GetOption(user_settings, 'no_invalid', 0 )
723723
call tohtml#GetOption(user_settings, 'whole_filler', 0 )
724724
call tohtml#GetOption(user_settings, 'use_xhtml', 0 )
725+
call tohtml#GetOption(user_settings, 'line_ids', user_settings.number_lines )
725726
" }}}
726727

727728
" override those settings that need it {{{
@@ -855,6 +856,20 @@ func! tohtml#GetUserSettings() "{{{
855856
let user_settings.no_invalid = 0
856857
endif
857858

859+
if exists('g:html_id_expr')
860+
let user_settings.id_suffix = eval(g:html_id_expr)
861+
if user_settings.id_suffix !~ '^[-_:.A-Za-z0-9]*$'
862+
echohl WarningMsg
863+
echomsg '2html: g:html_id_expr evaluated to invalid string for HTML id attributes'
864+
echomsg '2html: Omitting user-specified suffix'
865+
echohl None
866+
sleep 3
867+
let user_settings.id_suffix=""
868+
endif
869+
else
870+
let user_settings.id_suffix=""
871+
endif
872+
858873
" TODO: font
859874

860875
return user_settings

runtime/doc/syntax.txt

Lines changed: 53 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 7.3. Last change: 2013 Jun 24
1+
*syntax.txt* For Vim version 7.3. Last change: 2013 Jun 26
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -379,12 +379,12 @@ settings, depending on which syntax is active. Example: >
379379
2HTML *2html.vim* *convert-to-HTML*
380380

381381
This is not a syntax file itself, but a script that converts the current
382-
window into HTML. Vim opens a new window in which it builds the HTML file.
382+
window into HTML. Vim opens a new window in which it builds the HTML file.
383383

384-
After you save the resulting file, you can view it with any browser. The
385-
colors should be exactly the same as you see them in Vim. You can jump to
386-
specific lines by adding (for example) #L123 or #123 to the end of the URL in
387-
your browser's address bar (#123 only with javascript support). And with
384+
After you save the resulting file, you can view it with any browser. The
385+
colors should be exactly the same as you see them in Vim. With
386+
|g:html_line_ids| you can jump to specific lines by adding (for example) #L123
387+
or #123 to the end of the URL in your browser's address bar. And with
388388
|g:html_dynamic_folds| enabled, you can show or hide the text that is folded
389389
in Vim.
390390

@@ -425,15 +425,14 @@ and last line to be converted. Example, using the last set Visual area: >
425425
|g:html_end_line| to the start and end of the range,
426426
respectively. Default range is the entire buffer.
427427

428-
If the current window is part of a |diff|, unless
429-
|g:html_diff_one_file| is set, :TOhtml will convert
430-
all windows which are part of the diff in the current
431-
tab and place them side-by-side in a <table> element
432-
in the generated HTML. When this happens you can jump
433-
to lines in specific windows with (for example) #W1L42
434-
for line 42 in the first diffed window, or #W3L87 for
435-
line 87 in the third. Omitting the window ID will
436-
default to the first window if javascript is enabled.
428+
If the current window is part of a |diff|, unless
429+
|g:html_diff_one_file| is set, :TOhtml will convert
430+
all windows which are part of the diff in the current
431+
tab and place them side-by-side in a <table> element
432+
in the generated HTML. With |g:html_line_ids| you can
433+
jump to lines in specific windows with (for example)
434+
#W1L42 for line 42 in the first diffed window, or
435+
#W3L87 for line 87 in the third.
437436

438437
Examples: >
439438
@@ -443,9 +442,9 @@ and last line to be converted. Example, using the last set Visual area: >
443442
<
444443
*g:html_diff_one_file*
445444
Default: 0.
446-
When 0, all windows involved in a |diff| in the current tab page are converted
447-
to HTML and placed side-by-side in a <table> element.
448-
When 1, only the current buffer is converted.
445+
When 0, and using |:TOhtml| all windows involved in a |diff| in the current tab
446+
page are converted to HTML and placed side-by-side in a <table> element. When
447+
1, only the current buffer is converted.
449448
Example: >
450449
451450
let g:html_diff_one_file = 1
@@ -494,6 +493,23 @@ Force to omit the line numbers: >
494493
:let g:html_number_lines = 0
495494
Go back to the default to use 'number' by deleting the variable: >
496495
:unlet g:html_number_lines
496+
<
497+
*g:html_line_ids*
498+
Default: 1 if |g:html_number_lines| is set, 0 otherwise.
499+
When 1, adds an HTML id attribute to each line number, or to an empty <span>
500+
inserted for that purpose if no line numbers are shown. This ID attribute
501+
takes the form of L123 for single-buffer HTML pages, or W2L123 for diff-view
502+
pages, and is used to jump to a specific line (in a specific window of a diff
503+
view). Javascript is inserted to open any closed dynamic folds
504+
(|g:html_dynamic_folds|) containing the specificed line before jumping. The
505+
javascript also allows omitting the window ID in the url, and the leading L.
506+
For example: >
507+
508+
page.html#L123 jumps to line 123 in a single-buffer file
509+
page.html#123 does the same
510+
511+
diff.html#W1L42 jumps to line 42 in the first window in a diff
512+
diff.html#42 does the same
497513
<
498514
*g:html_use_css*
499515
Default: 1.
@@ -603,6 +619,25 @@ they will not be openable without a foldcolumn.
603619
>
604620
:let g:html_hover_unfold = 1
605621
<
622+
*g:html_id_expr*
623+
Default: ""
624+
Dynamic folding and jumping to line IDs rely on unique IDs within the document
625+
to work. If generated HTML is copied into a larger document, these IDs are no
626+
longer guaranteed to be unique. Set g:html_id_expr to an expression Vim can
627+
evaluate to get a unique string to append to each ID used in a given document,
628+
so that the full IDs will be unique even when combined with other content in a
629+
larger HTML document. Example, to append _ and the buffer number to each ID: >
630+
631+
:let g:html_id_expr = '"_".bufnr("%")'
632+
<
633+
To append a string "_mystring" to the end of each ID: >
634+
635+
:let g:html_id_expr = '"_mystring"'
636+
<
637+
Note, when converting a diff view to HTML, the expression will only be
638+
evaluated for the first window in the diff, and the result used for all the
639+
windows.
640+
606641
*TOhtml-wrap-text* *g:html_pre_wrap*
607642
Default: current 'wrap' setting.
608643
When 0, if |g:html_no_pre| is 0 or unset, the text in the generated HTML does

runtime/doc/tags

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,8 +5894,10 @@ g:html_encoding_override syntax.txt /*g:html_encoding_override*
58945894
g:html_end_line syntax.txt /*g:html_end_line*
58955895
g:html_expand_tabs syntax.txt /*g:html_expand_tabs*
58965896
g:html_hover_unfold syntax.txt /*g:html_hover_unfold*
5897+
g:html_id_expr syntax.txt /*g:html_id_expr*
58975898
g:html_ignore_conceal syntax.txt /*g:html_ignore_conceal*
58985899
g:html_ignore_folding syntax.txt /*g:html_ignore_folding*
5900+
g:html_line_ids syntax.txt /*g:html_line_ids*
58995901
g:html_no_foldcolumn syntax.txt /*g:html_no_foldcolumn*
59005902
g:html_no_invalid syntax.txt /*g:html_no_invalid*
59015903
g:html_no_pre syntax.txt /*g:html_no_pre*

runtime/doc/todo.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*todo.txt* For Vim version 7.3. Last change: 2013 Jun 24
1+
*todo.txt* For Vim version 7.3. Last change: 2013 Jun 26
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -36,7 +36,8 @@ not be repeated below, unless there is extra information.
3636

3737
--- Python interface
3838

39-
Test 86 fails on MS-Windows. (Taro Muraoka, 2013 Jun 24)
39+
Test 86 fails on MS-Windows, using backslashes instead of forward slashes.
40+
(Taro Muraoka, 2013 Jun 24)
4041
Can we fix this in code instead of in the test?
4142

4243
Python: ":py raw_input('prompt')" doesn't work. (Manu Hack)
@@ -65,6 +66,9 @@ see why it doesn't work.
6566

6667
Patch to fix finding toolbar bitmaps. Issue 129.
6768

69+
Patch 7.3.1200 doesn't fix the problem in all cases. (Hirohito Higashi, 2013
70+
Jun 24)
71+
6872
Patch to avoid clang warnings when building with Athena.
6973
(Dominique Pelle, 2013 Jun 22)
7074

@@ -202,10 +206,6 @@ register. It is reset after the next command. (Steve Vermeulen, 2013 Mar 16)
202206

203207
'ff' is wrong for one-line file without EOL. (Issue 77)
204208

205-
Can add a function to a dict using a weird key:
206-
let dict['/foo'] = function('tr')
207-
Disallow? (thinca, 2013 Jun 17)
208-
209209
Patch to set antialiasing style on Windows. (Ondrej Balaz, 2013 Mar 14)
210210
Needs a different check for CLEARTYPE_QUALITY.
211211

runtime/plugin/tohtml.vim

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim plugin for converting a syntax highlighted file to HTML.
22
" Maintainer: Ben Fritz <[email protected]>
3-
" Last Change: 2013 May 31
3+
" Last Change: 2013 Jun 12
44
"
55
" The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and
66
" $VIMRUNTIME/syntax/2html.vim
@@ -67,12 +67,18 @@
6767
if exists('g:loaded_2html_plugin')
6868
finish
6969
endif
70-
let g:loaded_2html_plugin = 'vim7.3_v13'
70+
let g:loaded_2html_plugin = 'vim7.3_v14'
7171

7272
"
7373
" Changelog: {{{
7474
"
75-
" 7.3_v13 (this version): Keep foldmethod at manual in the generated file and
75+
" 7.3_v14 (this version): Allow suppressing empty <span> created for line
76+
" number anchors when line numbers are not included,
77+
" using g:html_empty_anchors=0. Allow customizing
78+
" important IDs (like line IDs and fold IDs) using
79+
" g:html_id_expr evalutated when the buffer conversion
80+
" is started.
81+
" 7.3_v13 (2eb30f341e8d): Keep foldmethod at manual in the generated file and
7682
" insert modeline to set it to manual.
7783
" Fix bug: diff mode with 2 unsaved buffers creates a
7884
" duplicate of one buffer instead of including both.

0 commit comments

Comments
 (0)