Updated runtime files. New version of TOhtml plugin.

This commit is contained in:
Bram Moolenaar
2013-06-26 13:28:14 +02:00
parent b052fe0e2c
commit 31c31679e2
6 changed files with 177 additions and 105 deletions

View File

@ -1,6 +1,6 @@
" Vim autoload file for the tohtml plugin.
" Maintainer: Ben Fritz <fritzophrenic@gmail.com>
" Last Change: 2013 May 31
" Last Change: 2013 Jun 19
"
" Additional contributors:
"
@ -401,15 +401,15 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
call add(html, '</head>')
let body_line_num = len(html)
if !empty(s:settings.prevent_copy)
call add(html, "<body onload='FixCharWidth(); JumpToLine();'>")
call add(html, "<body onload='FixCharWidth();".(s:settings.line_ids ? " JumpToLine();" : "")."'>")
call add(html, "<!-- hidden divs used by javascript to get the width of a char -->")
call add(html, "<div id='oneCharWidth'>0</div>")
call add(html, "<div id='oneInputWidth'><input size='1' value='0'".tag_close."</div>")
call add(html, "<div id='oneEmWidth' style='width: 1em;'></div>")
else
call add(html, '<body onload="JumpToLine();">')
call add(html, '<body'.(s:settings.line_ids ? ' onload="JumpToLine();"' : '').'>')
endif
call add(html, "<table border='1' width='100%' id='vimCodeElement'>")
call add(html, "<table border='1' width='100%' id='vimCodeElement".s:settings.id_suffix."'>")
call add(html, '<tr>')
for buf in a:win_list
@ -475,7 +475,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
let temp = getline(1,'$')
" clean out id on the main content container because we already set it on
" the table
let temp[0] = substitute(temp[0], " id='vimCodeElement'", "", "")
let temp[0] = substitute(temp[0], " id='vimCodeElement[^']*'", "", "")
" undo deletion of start and end part
" so we can later save the file as valid html
" TODO: restore using grabbed lines if undolevel is 1?
@ -568,9 +568,9 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
\ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;',
\ ' if (inputWidth > goodWidth) {',
\ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {',
\ ' ratio += 5;',
\ ' }',
\ ' document.getElementById("vimCodeElement").className = "em"+ratio;',
\ ' ratio += 5;',
\ ' }',
\ ' document.getElementById("vimCodeElement'.s:settings.id_suffix.'").className = "em"+ratio;',
\ ' }',
\ '}'
\ ])
@ -596,7 +596,7 @@ func! tohtml#Diff2HTML(win_list, buf_list) "{{{
\ "",
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
\ " var node = lineElem;",
\ " while (node && node.id != 'vimCodeElement')",
\ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
\ " {",
\ " if (node.className == 'closed-fold')",
\ " {",
@ -722,6 +722,7 @@ func! tohtml#GetUserSettings() "{{{
call tohtml#GetOption(user_settings, 'no_invalid', 0 )
call tohtml#GetOption(user_settings, 'whole_filler', 0 )
call tohtml#GetOption(user_settings, 'use_xhtml', 0 )
call tohtml#GetOption(user_settings, 'line_ids', user_settings.number_lines )
" }}}
" override those settings that need it {{{
@ -855,6 +856,20 @@ func! tohtml#GetUserSettings() "{{{
let user_settings.no_invalid = 0
endif
if exists('g:html_id_expr')
let user_settings.id_suffix = eval(g:html_id_expr)
if user_settings.id_suffix !~ '^[-_:.A-Za-z0-9]*$'
echohl WarningMsg
echomsg '2html: g:html_id_expr evaluated to invalid string for HTML id attributes'
echomsg '2html: Omitting user-specified suffix'
echohl None
sleep 3
let user_settings.id_suffix=""
endif
else
let user_settings.id_suffix=""
endif
" TODO: font
return user_settings

View File

@ -1,4 +1,4 @@
*syntax.txt* For Vim version 7.3. Last change: 2013 Jun 24
*syntax.txt* For Vim version 7.3. Last change: 2013 Jun 26
VIM REFERENCE MANUAL by Bram Moolenaar
@ -379,12 +379,12 @@ settings, depending on which syntax is active. Example: >
2HTML *2html.vim* *convert-to-HTML*
This is not a syntax file itself, but a script that converts the current
window into HTML. Vim opens a new window in which it builds the HTML file.
window into HTML. Vim opens a new window in which it builds the HTML file.
After you save the resulting file, you can view it with any browser. The
colors should be exactly the same as you see them in Vim. You can jump to
specific lines by adding (for example) #L123 or #123 to the end of the URL in
your browser's address bar (#123 only with javascript support). And with
After you save the resulting file, you can view it with any browser. The
colors should be exactly the same as you see them in Vim. With
|g:html_line_ids| you can jump to specific lines by adding (for example) #L123
or #123 to the end of the URL in your browser's address bar. And with
|g:html_dynamic_folds| enabled, you can show or hide the text that is folded
in Vim.
@ -425,15 +425,14 @@ and last line to be converted. Example, using the last set Visual area: >
|g:html_end_line| to the start and end of the range,
respectively. Default range is the entire buffer.
If the current window is part of a |diff|, unless
|g:html_diff_one_file| is set, :TOhtml will convert
all windows which are part of the diff in the current
tab and place them side-by-side in a <table> element
in the generated HTML. When this happens you can jump
to lines in specific windows with (for example) #W1L42
for line 42 in the first diffed window, or #W3L87 for
line 87 in the third. Omitting the window ID will
default to the first window if javascript is enabled.
If the current window is part of a |diff|, unless
|g:html_diff_one_file| is set, :TOhtml will convert
all windows which are part of the diff in the current
tab and place them side-by-side in a <table> element
in the generated HTML. With |g:html_line_ids| you can
jump to lines in specific windows with (for example)
#W1L42 for line 42 in the first diffed window, or
#W3L87 for line 87 in the third.
Examples: >
@ -443,9 +442,9 @@ and last line to be converted. Example, using the last set Visual area: >
<
*g:html_diff_one_file*
Default: 0.
When 0, all windows involved in a |diff| in the current tab page are converted
to HTML and placed side-by-side in a <table> element.
When 1, only the current buffer is converted.
When 0, and using |:TOhtml| all windows involved in a |diff| in the current tab
page are converted to HTML and placed side-by-side in a <table> element. When
1, only the current buffer is converted.
Example: >
let g:html_diff_one_file = 1
@ -494,6 +493,23 @@ Force to omit the line numbers: >
:let g:html_number_lines = 0
Go back to the default to use 'number' by deleting the variable: >
:unlet g:html_number_lines
<
*g:html_line_ids*
Default: 1 if |g:html_number_lines| is set, 0 otherwise.
When 1, adds an HTML id attribute to each line number, or to an empty <span>
inserted for that purpose if no line numbers are shown. This ID attribute
takes the form of L123 for single-buffer HTML pages, or W2L123 for diff-view
pages, and is used to jump to a specific line (in a specific window of a diff
view). Javascript is inserted to open any closed dynamic folds
(|g:html_dynamic_folds|) containing the specificed line before jumping. The
javascript also allows omitting the window ID in the url, and the leading L.
For example: >
page.html#L123 jumps to line 123 in a single-buffer file
page.html#123 does the same
diff.html#W1L42 jumps to line 42 in the first window in a diff
diff.html#42 does the same
<
*g:html_use_css*
Default: 1.
@ -603,6 +619,25 @@ they will not be openable without a foldcolumn.
>
:let g:html_hover_unfold = 1
<
*g:html_id_expr*
Default: ""
Dynamic folding and jumping to line IDs rely on unique IDs within the document
to work. If generated HTML is copied into a larger document, these IDs are no
longer guaranteed to be unique. Set g:html_id_expr to an expression Vim can
evaluate to get a unique string to append to each ID used in a given document,
so that the full IDs will be unique even when combined with other content in a
larger HTML document. Example, to append _ and the buffer number to each ID: >
:let g:html_id_expr = '"_".bufnr("%")'
<
To append a string "_mystring" to the end of each ID: >
:let g:html_id_expr = '"_mystring"'
<
Note, when converting a diff view to HTML, the expression will only be
evaluated for the first window in the diff, and the result used for all the
windows.
*TOhtml-wrap-text* *g:html_pre_wrap*
Default: current 'wrap' setting.
When 0, if |g:html_no_pre| is 0 or unset, the text in the generated HTML does

View File

@ -5894,8 +5894,10 @@ g:html_encoding_override syntax.txt /*g:html_encoding_override*
g:html_end_line syntax.txt /*g:html_end_line*
g:html_expand_tabs syntax.txt /*g:html_expand_tabs*
g:html_hover_unfold syntax.txt /*g:html_hover_unfold*
g:html_id_expr syntax.txt /*g:html_id_expr*
g:html_ignore_conceal syntax.txt /*g:html_ignore_conceal*
g:html_ignore_folding syntax.txt /*g:html_ignore_folding*
g:html_line_ids syntax.txt /*g:html_line_ids*
g:html_no_foldcolumn syntax.txt /*g:html_no_foldcolumn*
g:html_no_invalid syntax.txt /*g:html_no_invalid*
g:html_no_pre syntax.txt /*g:html_no_pre*

View File

@ -1,4 +1,4 @@
*todo.txt* For Vim version 7.3. Last change: 2013 Jun 24
*todo.txt* For Vim version 7.3. Last change: 2013 Jun 26
VIM REFERENCE MANUAL by Bram Moolenaar
@ -36,7 +36,8 @@ not be repeated below, unless there is extra information.
--- Python interface
Test 86 fails on MS-Windows. (Taro Muraoka, 2013 Jun 24)
Test 86 fails on MS-Windows, using backslashes instead of forward slashes.
(Taro Muraoka, 2013 Jun 24)
Can we fix this in code instead of in the test?
Python: ":py raw_input('prompt')" doesn't work. (Manu Hack)
@ -65,6 +66,9 @@ see why it doesn't work.
Patch to fix finding toolbar bitmaps. Issue 129.
Patch 7.3.1200 doesn't fix the problem in all cases. (Hirohito Higashi, 2013
Jun 24)
Patch to avoid clang warnings when building with Athena.
(Dominique Pelle, 2013 Jun 22)
@ -202,10 +206,6 @@ register. It is reset after the next command. (Steve Vermeulen, 2013 Mar 16)
'ff' is wrong for one-line file without EOL. (Issue 77)
Can add a function to a dict using a weird key:
let dict['/foo'] = function('tr')
Disallow? (thinca, 2013 Jun 17)
Patch to set antialiasing style on Windows. (Ondrej Balaz, 2013 Mar 14)
Needs a different check for CLEARTYPE_QUALITY.

View File

@ -1,6 +1,6 @@
" Vim plugin for converting a syntax highlighted file to HTML.
" Maintainer: Ben Fritz <fritzophrenic@gmail.com>
" Last Change: 2013 May 31
" Last Change: 2013 Jun 12
"
" The core of the code is in $VIMRUNTIME/autoload/tohtml.vim and
" $VIMRUNTIME/syntax/2html.vim
@ -67,12 +67,18 @@
if exists('g:loaded_2html_plugin')
finish
endif
let g:loaded_2html_plugin = 'vim7.3_v13'
let g:loaded_2html_plugin = 'vim7.3_v14'
"
" Changelog: {{{
"
" 7.3_v13 (this version): Keep foldmethod at manual in the generated file and
" 7.3_v14 (this version): Allow suppressing empty <span> created for line
" number anchors when line numbers are not included,
" using g:html_empty_anchors=0. Allow customizing
" important IDs (like line IDs and fold IDs) using
" g:html_id_expr evalutated when the buffer conversion
" is started.
" 7.3_v13 (2eb30f341e8d): Keep foldmethod at manual in the generated file and
" insert modeline to set it to manual.
" Fix bug: diff mode with 2 unsaved buffers creates a
" duplicate of one buffer instead of including both.

View File

@ -1,6 +1,6 @@
" Vim syntax support file
" Maintainer: Ben Fritz <fritzophrenic@gmail.com>
" Last Change: 2013 May 31
" Last Change: 2013 Jun 19
"
" Additional contributors:
"
@ -450,30 +450,42 @@ endfun
" element is supposed to be unselectable or not
if s:settings.prevent_copy =~# 'n'
if s:settings.number_lines
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
if a:lnr > 0
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.'" ', 1)
else
if s:settings.line_ids
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
if a:lnr > 0
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)
else
return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
endif
endfun
else
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1)
endif
endfun
else
endfun
endif
elseif s:settings.line_ids
" if lines are not being numbered the only reason this function gets called
" is to put the line IDs on each line; "text" will be emtpy but lnr will
" always be non-zero, however we don't want to use the <input> because that
" won't work as nice for empty text
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
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.'" ', 0)
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)
endfun
endif
else
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
if a:lnr > 0
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.'" ', 0)
else
if s:settings.line_ids
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
if a:lnr > 0
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)
else
return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
endif
endfun
else
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0)
endif
endfun
endfun
endif
endif
if s:settings.prevent_copy =~# 'd'
function! s:HtmlFormat_d(text, style_id, diff_style_id)
@ -818,50 +830,52 @@ if s:settings.dynamic_folds
\ ])
endif
" insert javascript to get IDs from line numbers, and to open a fold before
" jumping to any lines contained therein
call extend(s:lines, [
\ "",
\ "/* function to open any folds containing a jumped-to line before jumping to it */",
\ "function JumpToLine()",
\ "{",
\ " var lineNum;",
\ " lineNum = window.location.hash;",
\ " lineNum = lineNum.substr(1); /* strip off '#' */",
\ "",
\ " if (lineNum.indexOf('L') == -1) {",
\ " lineNum = 'L'+lineNum;",
\ " }",
\ " lineElem = document.getElementById(lineNum);"
\ ])
if s:settings.dynamic_folds
if s:settings.line_ids
" insert javascript to get IDs from line numbers, and to open a fold before
" jumping to any lines contained therein
call extend(s:lines, [
\ "",
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
\ " var node = lineElem;",
\ " while (node && node.id != 'vimCodeElement')",
\ " {",
\ " if (node.className == 'closed-fold')",
\ " {",
\ " node.className = 'open-fold';",
\ " }",
\ " node = node.parentNode;",
\ "/* function to open any folds containing a jumped-to line before jumping to it */",
\ "function JumpToLine()",
\ "{",
\ " var lineNum;",
\ " lineNum = window.location.hash;",
\ " lineNum = lineNum.substr(1); /* strip off '#' */",
\ "",
\ " if (lineNum.indexOf('L') == -1) {",
\ " lineNum = 'L'+lineNum;",
\ " }",
\ " lineElem = document.getElementById(lineNum);"
\ ])
if s:settings.dynamic_folds
call extend(s:lines, [
\ "",
\ " /* navigate upwards in the DOM tree to open all folds containing the line */",
\ " var node = lineElem;",
\ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')",
\ " {",
\ " if (node.className == 'closed-fold')",
\ " {",
\ " node.className = 'open-fold';",
\ " }",
\ " node = node.parentNode;",
\ " }",
\ ])
endif
call extend(s:lines, [
\ " /* Always jump to new location even if the line was hidden inside a fold, or",
\ " * we corrected the raw number to a line ID.",
\ " */",
\ " if (lineElem) {",
\ " lineElem.scrollIntoView(true);",
\ " }",
\ " return true;",
\ "}",
\ "if ('onhashchange' in window) {",
\ " window.onhashchange = JumpToLine;",
\ "}"
\ ])
endif
call extend(s:lines, [
\ " /* Always jump to new location even if the line was hidden inside a fold, or",
\ " * we corrected the raw number to a line ID.",
\ " */",
\ " if (lineElem) {",
\ " lineElem.scrollIntoView(true);",
\ " }",
\ " return true;",
\ "}",
\ "if ('onhashchange' in window) {",
\ " window.onhashchange = JumpToLine;",
\ "}"
\ ])
" Small text columns like the foldcolumn and line number column need a weird
" hack to work around Webkit's and (in versions prior to 9) IE's lack of support
@ -914,9 +928,9 @@ if !empty(s:settings.prevent_copy)
\ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;',
\ ' if (inputWidth > goodWidth) {',
\ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {',
\ ' ratio += 5;',
\ ' }',
\ ' document.getElementById("vimCodeElement").className = "em"+ratio;',
\ ' ratio += 5;',
\ ' }',
\ ' document.getElementById("vimCodeElement'.s:settings.id_suffix.'").className = "em"+ratio;',
\ ' }',
\ '}'
\ ])
@ -932,22 +946,22 @@ call extend(s:lines, [
call extend(s:lines, ["</head>"])
if !empty(s:settings.prevent_copy)
call extend(s:lines,
\ ["<body onload='FixCharWidth(); JumpToLine();'>",
\ ["<body onload='FixCharWidth();".(s:settings.line_ids ? " JumpToLine();" : "")."'>",
\ "<!-- hidden divs used by javascript to get the width of a char -->",
\ "<div id='oneCharWidth'>0</div>",
\ "<div id='oneInputWidth'><input size='1' value='0'".s:tag_close."</div>",
\ "<div id='oneEmWidth' style='width: 1em;'></div>"
\ ])
else
call extend(s:lines, ["<body onload='JumpToLine();'>"])
call extend(s:lines, ["<body".(s:settings.line_ids ? " onload='JumpToLine();'" : "").">"])
endif
if s:settings.no_pre
" if we're not using CSS we use a font tag which can't have a div inside
if s:settings.use_css
call extend(s:lines, ["<div id='vimCodeElement'>"])
call extend(s:lines, ["<div id='vimCodeElement".s:settings.id_suffix."'>"])
endif
else
call extend(s:lines, ["<pre id='vimCodeElement'>"])
call extend(s:lines, ["<pre id='vimCodeElement".s:settings.id_suffix."'>"])
endif
exe s:orgwin . "wincmd w"
@ -1364,7 +1378,7 @@ while s:lnum <= s:end
let s:foldId = s:foldId + 1
let s:new .= "<span id='"
let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "")
let s:new .= "fold".s:foldId."' class='".s:allfolds[0].type."'>"
let s:new .= "fold".s:foldId.s:settings.id_suffix."' class='".s:allfolds[0].type."'>"
" Unless disabled, add a fold column for the opening line of a fold.
@ -1376,19 +1390,19 @@ while s:lnum <= s:end
" add fold column that can open the new fold
if s:allfolds[0].level > 1 && s:firstfold
let s:new = s:new . s:FoldColumn_build('|', s:allfolds[0].level - 1, 0, "",
\ 'toggle-open FoldColumn','javascript:toggleFold("fold'.s:foldstack[0].id.'");')
\ 'toggle-open FoldColumn','javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");')
endif
" add the filler spaces separately from the '+' char so that it can be
" shown/hidden separately during a hover unfold
let s:new = s:new . s:FoldColumn_build("+", 1, 0, "",
\ 'toggle-open FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");')
\ 'toggle-open FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
" If this is not the last fold we're opening on this line, we need
" to keep the filler spaces hidden if the fold is opened by mouse
" hover. If it is the last fold to open in the line, we shouldn't hide
" them, so don't apply the toggle-filler class.
let s:new = s:new . s:FoldColumn_build(" ", 1, s:foldcolumn - s:allfolds[0].level - 1, "",
\ 'toggle-open FoldColumn'. (get(s:allfolds, 1, {'firstline': 0}).firstline == s:lnum ?" toggle-filler" :""),
\ 'javascript:toggleFold("fold'.s:foldId.'");')
\ 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
" add fold column that can close the new fold
" only add extra blank space if we aren't opening another fold on the
@ -1402,11 +1416,11 @@ while s:lnum <= s:end
" the first fold in a line has '|' characters from folds opened in
" previous lines, before the '-' for this fold
let s:new .= s:FoldColumn_build('|', s:allfolds[0].level - 1, s:extra_space, '-',
\ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");')
\ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
else
" any subsequent folds in the line only add a single '-'
let s:new = s:new . s:FoldColumn_build("-", 1, s:extra_space, "",
\ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");')
\ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");')
endif
let s:firstfold = 0
endif
@ -1440,7 +1454,7 @@ while s:lnum <= s:end
" add the fold column for folds not on the opening line
if get(s:foldstack, 0).firstline < s:lnum
let s:new = s:new . s:FoldColumn_build('|', s:foldstack[0].level, s:foldcolumn - s:foldstack[0].level, "",
\ 'FoldColumn', 'javascript:toggleFold("fold'.s:foldstack[0].id.'");')
\ 'FoldColumn', 'javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");')
endif
endif
endif
@ -1449,7 +1463,7 @@ while s:lnum <= s:end
" Now continue with the unfolded line text
if s:settings.number_lines
let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0, s:lnum)
else
elseif s:settings.line_ids
let s:new = s:new . s:HtmlFormat_n("", s:LINENR_ID, 0, s:lnum)
endif