Mercurial > vim
comparison runtime/syntax/2html.vim @ 5003:ad6996a23e3e
Updated runtime files. New version of TOhtml plugin.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 26 Jun 2013 13:28:14 +0200 |
parents | 2eb30f341e8d |
children | f7add3891e95 |
comparison
equal
deleted
inserted
replaced
5002:2f5a78a77361 | 5003:ad6996a23e3e |
---|---|
1 " Vim syntax support file | 1 " Vim syntax support file |
2 " Maintainer: Ben Fritz <fritzophrenic@gmail.com> | 2 " Maintainer: Ben Fritz <fritzophrenic@gmail.com> |
3 " Last Change: 2013 May 31 | 3 " Last Change: 2013 Jun 19 |
4 " | 4 " |
5 " Additional contributors: | 5 " Additional contributors: |
6 " | 6 " |
7 " Original by Bram Moolenaar <Bram@vim.org> | 7 " Original by Bram Moolenaar <Bram@vim.org> |
8 " Modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz> | 8 " Modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz> |
448 | 448 |
449 " set up functions to call HtmlFormat in certain ways based on whether the | 449 " set up functions to call HtmlFormat in certain ways based on whether the |
450 " element is supposed to be unselectable or not | 450 " element is supposed to be unselectable or not |
451 if s:settings.prevent_copy =~# 'n' | 451 if s:settings.prevent_copy =~# 'n' |
452 if s:settings.number_lines | 452 if s:settings.number_lines |
453 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) | 453 if s:settings.line_ids |
454 if a:lnr > 0 | 454 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) |
455 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) | 455 if a:lnr > 0 |
456 else | 456 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) |
457 else | |
458 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) | |
459 endif | |
460 endfun | |
461 else | |
462 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) | |
457 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) | 463 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) |
458 endif | 464 endfun |
459 endfun | 465 endif |
460 else | 466 elseif s:settings.line_ids |
461 " if lines are not being numbered the only reason this function gets called | 467 " if lines are not being numbered the only reason this function gets called |
462 " is to put the line IDs on each line; "text" will be emtpy but lnr will | 468 " is to put the line IDs on each line; "text" will be emtpy but lnr will |
463 " always be non-zero, however we don't want to use the <input> because that | 469 " always be non-zero, however we don't want to use the <input> because that |
464 " won't work as nice for empty text | 470 " won't work as nice for empty text |
465 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) | 471 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) |
466 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) | 472 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) |
467 endfun | 473 endfun |
468 endif | 474 endif |
469 else | 475 else |
470 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) | 476 if s:settings.line_ids |
471 if a:lnr > 0 | 477 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) |
472 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) | 478 if a:lnr > 0 |
473 else | 479 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) |
480 else | |
481 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0) | |
482 endif | |
483 endfun | |
484 else | |
485 function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr) | |
474 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0) | 486 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 0) |
475 endif | 487 endfun |
476 endfun | 488 endif |
477 endif | 489 endif |
478 if s:settings.prevent_copy =~# 'd' | 490 if s:settings.prevent_copy =~# 'd' |
479 function! s:HtmlFormat_d(text, style_id, diff_style_id) | 491 function! s:HtmlFormat_d(text, style_id, diff_style_id) |
480 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) | 492 return s:HtmlFormat(a:text, a:style_id, a:diff_style_id, "", 1) |
481 endfun | 493 endfun |
816 \ " }", | 828 \ " }", |
817 \ "}" | 829 \ "}" |
818 \ ]) | 830 \ ]) |
819 endif | 831 endif |
820 | 832 |
821 " insert javascript to get IDs from line numbers, and to open a fold before | 833 if s:settings.line_ids |
822 " jumping to any lines contained therein | 834 " insert javascript to get IDs from line numbers, and to open a fold before |
823 call extend(s:lines, [ | 835 " jumping to any lines contained therein |
824 \ "", | |
825 \ "/* function to open any folds containing a jumped-to line before jumping to it */", | |
826 \ "function JumpToLine()", | |
827 \ "{", | |
828 \ " var lineNum;", | |
829 \ " lineNum = window.location.hash;", | |
830 \ " lineNum = lineNum.substr(1); /* strip off '#' */", | |
831 \ "", | |
832 \ " if (lineNum.indexOf('L') == -1) {", | |
833 \ " lineNum = 'L'+lineNum;", | |
834 \ " }", | |
835 \ " lineElem = document.getElementById(lineNum);" | |
836 \ ]) | |
837 if s:settings.dynamic_folds | |
838 call extend(s:lines, [ | 836 call extend(s:lines, [ |
839 \ "", | 837 \ "", |
840 \ " /* navigate upwards in the DOM tree to open all folds containing the line */", | 838 \ "/* function to open any folds containing a jumped-to line before jumping to it */", |
841 \ " var node = lineElem;", | 839 \ "function JumpToLine()", |
842 \ " while (node && node.id != 'vimCodeElement')", | 840 \ "{", |
843 \ " {", | 841 \ " var lineNum;", |
844 \ " if (node.className == 'closed-fold')", | 842 \ " lineNum = window.location.hash;", |
845 \ " {", | 843 \ " lineNum = lineNum.substr(1); /* strip off '#' */", |
846 \ " node.className = 'open-fold';", | 844 \ "", |
847 \ " }", | 845 \ " if (lineNum.indexOf('L') == -1) {", |
848 \ " node = node.parentNode;", | 846 \ " lineNum = 'L'+lineNum;", |
849 \ " }", | 847 \ " }", |
848 \ " lineElem = document.getElementById(lineNum);" | |
850 \ ]) | 849 \ ]) |
851 endif | 850 if s:settings.dynamic_folds |
852 call extend(s:lines, [ | 851 call extend(s:lines, [ |
853 \ " /* Always jump to new location even if the line was hidden inside a fold, or", | 852 \ "", |
854 \ " * we corrected the raw number to a line ID.", | 853 \ " /* navigate upwards in the DOM tree to open all folds containing the line */", |
855 \ " */", | 854 \ " var node = lineElem;", |
856 \ " if (lineElem) {", | 855 \ " while (node && node.id != 'vimCodeElement".s:settings.id_suffix."')", |
857 \ " lineElem.scrollIntoView(true);", | 856 \ " {", |
858 \ " }", | 857 \ " if (node.className == 'closed-fold')", |
859 \ " return true;", | 858 \ " {", |
860 \ "}", | 859 \ " node.className = 'open-fold';", |
861 \ "if ('onhashchange' in window) {", | 860 \ " }", |
862 \ " window.onhashchange = JumpToLine;", | 861 \ " node = node.parentNode;", |
863 \ "}" | 862 \ " }", |
864 \ ]) | 863 \ ]) |
864 endif | |
865 call extend(s:lines, [ | |
866 \ " /* Always jump to new location even if the line was hidden inside a fold, or", | |
867 \ " * we corrected the raw number to a line ID.", | |
868 \ " */", | |
869 \ " if (lineElem) {", | |
870 \ " lineElem.scrollIntoView(true);", | |
871 \ " }", | |
872 \ " return true;", | |
873 \ "}", | |
874 \ "if ('onhashchange' in window) {", | |
875 \ " window.onhashchange = JumpToLine;", | |
876 \ "}" | |
877 \ ]) | |
878 endif | |
865 | 879 |
866 " Small text columns like the foldcolumn and line number column need a weird | 880 " Small text columns like the foldcolumn and line number column need a weird |
867 " hack to work around Webkit's and (in versions prior to 9) IE's lack of support | 881 " hack to work around Webkit's and (in versions prior to 9) IE's lack of support |
868 " for the 'ch' unit without messing up Opera, which also doesn't support it but | 882 " for the 'ch' unit without messing up Opera, which also doesn't support it but |
869 " works anyway. | 883 " works anyway. |
912 \ ' var ratio = 5;', | 926 \ ' var ratio = 5;', |
913 \ ' var inputWidth = document.getElementById("oneInputWidth").clientWidth;', | 927 \ ' var inputWidth = document.getElementById("oneInputWidth").clientWidth;', |
914 \ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;', | 928 \ ' var emWidth = document.getElementById("oneEmWidth").clientWidth;', |
915 \ ' if (inputWidth > goodWidth) {', | 929 \ ' if (inputWidth > goodWidth) {', |
916 \ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {', | 930 \ ' while (ratio < 100*goodWidth/emWidth && ratio < 100) {', |
917 \ ' ratio += 5;', | 931 \ ' ratio += 5;', |
918 \ ' }', | 932 \ ' }', |
919 \ ' document.getElementById("vimCodeElement").className = "em"+ratio;', | 933 \ ' document.getElementById("vimCodeElement'.s:settings.id_suffix.'").className = "em"+ratio;', |
920 \ ' }', | 934 \ ' }', |
921 \ '}' | 935 \ '}' |
922 \ ]) | 936 \ ]) |
923 endif | 937 endif |
924 | 938 |
930 \ ]) | 944 \ ]) |
931 | 945 |
932 call extend(s:lines, ["</head>"]) | 946 call extend(s:lines, ["</head>"]) |
933 if !empty(s:settings.prevent_copy) | 947 if !empty(s:settings.prevent_copy) |
934 call extend(s:lines, | 948 call extend(s:lines, |
935 \ ["<body onload='FixCharWidth(); JumpToLine();'>", | 949 \ ["<body onload='FixCharWidth();".(s:settings.line_ids ? " JumpToLine();" : "")."'>", |
936 \ "<!-- hidden divs used by javascript to get the width of a char -->", | 950 \ "<!-- hidden divs used by javascript to get the width of a char -->", |
937 \ "<div id='oneCharWidth'>0</div>", | 951 \ "<div id='oneCharWidth'>0</div>", |
938 \ "<div id='oneInputWidth'><input size='1' value='0'".s:tag_close."</div>", | 952 \ "<div id='oneInputWidth'><input size='1' value='0'".s:tag_close."</div>", |
939 \ "<div id='oneEmWidth' style='width: 1em;'></div>" | 953 \ "<div id='oneEmWidth' style='width: 1em;'></div>" |
940 \ ]) | 954 \ ]) |
941 else | 955 else |
942 call extend(s:lines, ["<body onload='JumpToLine();'>"]) | 956 call extend(s:lines, ["<body".(s:settings.line_ids ? " onload='JumpToLine();'" : "").">"]) |
943 endif | 957 endif |
944 if s:settings.no_pre | 958 if s:settings.no_pre |
945 " if we're not using CSS we use a font tag which can't have a div inside | 959 " if we're not using CSS we use a font tag which can't have a div inside |
946 if s:settings.use_css | 960 if s:settings.use_css |
947 call extend(s:lines, ["<div id='vimCodeElement'>"]) | 961 call extend(s:lines, ["<div id='vimCodeElement".s:settings.id_suffix."'>"]) |
948 endif | 962 endif |
949 else | 963 else |
950 call extend(s:lines, ["<pre id='vimCodeElement'>"]) | 964 call extend(s:lines, ["<pre id='vimCodeElement".s:settings.id_suffix."'>"]) |
951 endif | 965 endif |
952 | 966 |
953 exe s:orgwin . "wincmd w" | 967 exe s:orgwin . "wincmd w" |
954 | 968 |
955 " caches of style data | 969 " caches of style data |
1362 let s:firstfold = 1 | 1376 let s:firstfold = 1 |
1363 while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum | 1377 while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum |
1364 let s:foldId = s:foldId + 1 | 1378 let s:foldId = s:foldId + 1 |
1365 let s:new .= "<span id='" | 1379 let s:new .= "<span id='" |
1366 let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "") | 1380 let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "") |
1367 let s:new .= "fold".s:foldId."' class='".s:allfolds[0].type."'>" | 1381 let s:new .= "fold".s:foldId.s:settings.id_suffix."' class='".s:allfolds[0].type."'>" |
1368 | 1382 |
1369 | 1383 |
1370 " Unless disabled, add a fold column for the opening line of a fold. | 1384 " Unless disabled, add a fold column for the opening line of a fold. |
1371 " | 1385 " |
1372 " Note that dynamic folds require using css so we just use css to take | 1386 " Note that dynamic folds require using css so we just use css to take |
1374 " html_no_pre to make it easier | 1388 " html_no_pre to make it easier |
1375 if !s:settings.no_foldcolumn | 1389 if !s:settings.no_foldcolumn |
1376 " add fold column that can open the new fold | 1390 " add fold column that can open the new fold |
1377 if s:allfolds[0].level > 1 && s:firstfold | 1391 if s:allfolds[0].level > 1 && s:firstfold |
1378 let s:new = s:new . s:FoldColumn_build('|', s:allfolds[0].level - 1, 0, "", | 1392 let s:new = s:new . s:FoldColumn_build('|', s:allfolds[0].level - 1, 0, "", |
1379 \ 'toggle-open FoldColumn','javascript:toggleFold("fold'.s:foldstack[0].id.'");') | 1393 \ 'toggle-open FoldColumn','javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");') |
1380 endif | 1394 endif |
1381 " add the filler spaces separately from the '+' char so that it can be | 1395 " add the filler spaces separately from the '+' char so that it can be |
1382 " shown/hidden separately during a hover unfold | 1396 " shown/hidden separately during a hover unfold |
1383 let s:new = s:new . s:FoldColumn_build("+", 1, 0, "", | 1397 let s:new = s:new . s:FoldColumn_build("+", 1, 0, "", |
1384 \ 'toggle-open FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");') | 1398 \ 'toggle-open FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");') |
1385 " If this is not the last fold we're opening on this line, we need | 1399 " If this is not the last fold we're opening on this line, we need |
1386 " to keep the filler spaces hidden if the fold is opened by mouse | 1400 " to keep the filler spaces hidden if the fold is opened by mouse |
1387 " hover. If it is the last fold to open in the line, we shouldn't hide | 1401 " hover. If it is the last fold to open in the line, we shouldn't hide |
1388 " them, so don't apply the toggle-filler class. | 1402 " them, so don't apply the toggle-filler class. |
1389 let s:new = s:new . s:FoldColumn_build(" ", 1, s:foldcolumn - s:allfolds[0].level - 1, "", | 1403 let s:new = s:new . s:FoldColumn_build(" ", 1, s:foldcolumn - s:allfolds[0].level - 1, "", |
1390 \ 'toggle-open FoldColumn'. (get(s:allfolds, 1, {'firstline': 0}).firstline == s:lnum ?" toggle-filler" :""), | 1404 \ 'toggle-open FoldColumn'. (get(s:allfolds, 1, {'firstline': 0}).firstline == s:lnum ?" toggle-filler" :""), |
1391 \ 'javascript:toggleFold("fold'.s:foldId.'");') | 1405 \ 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");') |
1392 | 1406 |
1393 " add fold column that can close the new fold | 1407 " add fold column that can close the new fold |
1394 " only add extra blank space if we aren't opening another fold on the | 1408 " only add extra blank space if we aren't opening another fold on the |
1395 " same line | 1409 " same line |
1396 if get(s:allfolds, 1, {'firstline': 0}).firstline != s:lnum | 1410 if get(s:allfolds, 1, {'firstline': 0}).firstline != s:lnum |
1400 endif | 1414 endif |
1401 if s:firstfold | 1415 if s:firstfold |
1402 " the first fold in a line has '|' characters from folds opened in | 1416 " the first fold in a line has '|' characters from folds opened in |
1403 " previous lines, before the '-' for this fold | 1417 " previous lines, before the '-' for this fold |
1404 let s:new .= s:FoldColumn_build('|', s:allfolds[0].level - 1, s:extra_space, '-', | 1418 let s:new .= s:FoldColumn_build('|', s:allfolds[0].level - 1, s:extra_space, '-', |
1405 \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");') | 1419 \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");') |
1406 else | 1420 else |
1407 " any subsequent folds in the line only add a single '-' | 1421 " any subsequent folds in the line only add a single '-' |
1408 let s:new = s:new . s:FoldColumn_build("-", 1, s:extra_space, "", | 1422 let s:new = s:new . s:FoldColumn_build("-", 1, s:extra_space, "", |
1409 \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.'");') | 1423 \ 'toggle-closed FoldColumn', 'javascript:toggleFold("fold'.s:foldId.s:settings.id_suffix.'");') |
1410 endif | 1424 endif |
1411 let s:firstfold = 0 | 1425 let s:firstfold = 0 |
1412 endif | 1426 endif |
1413 | 1427 |
1414 " Add fold text, moving the span ending to the next line so collapsing | 1428 " Add fold text, moving the span ending to the next line so collapsing |
1438 endif | 1452 endif |
1439 else | 1453 else |
1440 " add the fold column for folds not on the opening line | 1454 " add the fold column for folds not on the opening line |
1441 if get(s:foldstack, 0).firstline < s:lnum | 1455 if get(s:foldstack, 0).firstline < s:lnum |
1442 let s:new = s:new . s:FoldColumn_build('|', s:foldstack[0].level, s:foldcolumn - s:foldstack[0].level, "", | 1456 let s:new = s:new . s:FoldColumn_build('|', s:foldstack[0].level, s:foldcolumn - s:foldstack[0].level, "", |
1443 \ 'FoldColumn', 'javascript:toggleFold("fold'.s:foldstack[0].id.'");') | 1457 \ 'FoldColumn', 'javascript:toggleFold("fold'.s:foldstack[0].id.s:settings.id_suffix.'");') |
1444 endif | 1458 endif |
1445 endif | 1459 endif |
1446 endif | 1460 endif |
1447 endif | 1461 endif |
1448 | 1462 |
1449 " Now continue with the unfolded line text | 1463 " Now continue with the unfolded line text |
1450 if s:settings.number_lines | 1464 if s:settings.number_lines |
1451 let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0, s:lnum) | 1465 let s:new = s:new . s:HtmlFormat_n(s:numcol, s:LINENR_ID, 0, s:lnum) |
1452 else | 1466 elseif s:settings.line_ids |
1453 let s:new = s:new . s:HtmlFormat_n("", s:LINENR_ID, 0, s:lnum) | 1467 let s:new = s:new . s:HtmlFormat_n("", s:LINENR_ID, 0, s:lnum) |
1454 endif | 1468 endif |
1455 | 1469 |
1456 " Get the diff attribute, if any. | 1470 " Get the diff attribute, if any. |
1457 let s:diffattr = diff_hlID(s:lnum, 1) | 1471 let s:diffattr = diff_hlID(s:lnum, 1) |