Mercurial > vim
comparison runtime/autoload/tohtml.vim @ 4681:2eb30f341e8d
Updated runtime files and translations.
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Sat, 01 Jun 2013 14:50:56 +0200 |
parents | 9910cbff5f16 |
children | ad6996a23e3e |
comparison
equal
deleted
inserted
replaced
4680:fd8cc7fbc273 | 4681:2eb30f341e8d |
---|---|
1 " Vim autoload file for the tohtml plugin. | 1 " Vim autoload file for the tohtml plugin. |
2 " Maintainer: Ben Fritz <fritzophrenic@gmail.com> | 2 " Maintainer: Ben Fritz <fritzophrenic@gmail.com> |
3 " Last Change: 2012 Jun 30 | 3 " Last Change: 2013 May 31 |
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 " Diff2HTML() added by Christian Brabandt <cb@256bit.org> | 8 " Diff2HTML() added by Christian Brabandt <cb@256bit.org> |
399 \ : 'none'). '"'.tag_close) | 399 \ : 'none'). '"'.tag_close) |
400 | 400 |
401 call add(html, '</head>') | 401 call add(html, '</head>') |
402 let body_line_num = len(html) | 402 let body_line_num = len(html) |
403 if !empty(s:settings.prevent_copy) | 403 if !empty(s:settings.prevent_copy) |
404 call add(html, "<body onload='FixCharWidth();'>") | 404 call add(html, "<body onload='FixCharWidth(); JumpToLine();'>") |
405 call add(html, "<!-- hidden divs used by javascript to get the width of a char -->") | 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>") | 406 call add(html, "<div id='oneCharWidth'>0</div>") |
407 call add(html, "<div id='oneInputWidth'><input size='1' value='0'".tag_close."</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>") | 408 call add(html, "<div id='oneEmWidth' style='width: 1em;'></div>") |
409 else | 409 else |
410 call add(html, '<body>') | 410 call add(html, '<body onload="JumpToLine();">') |
411 endif | 411 endif |
412 call add(html, "<table border='1' width='100%' id='vimCodeElement'>") | 412 call add(html, "<table border='1' width='100%' id='vimCodeElement'>") |
413 | 413 |
414 call add(html, '<tr>') | 414 call add(html, '<tr>') |
415 for buf in a:win_list | 415 for buf in a:win_list |
501 call add(html, '</tr>') | 501 call add(html, '</tr>') |
502 call add(html, '</table>') | 502 call add(html, '</table>') |
503 call add(html, s:body_end_line) | 503 call add(html, s:body_end_line) |
504 call add(html, '</html>') | 504 call add(html, '</html>') |
505 | 505 |
506 " The generated HTML is admittedly ugly and takes a LONG time to fold. | |
507 " Make sure the user doesn't do syntax folding when loading a generated file, | |
508 " using a modeline. | |
509 call add(html, '<!-- vim: set foldmethod=manual : -->') | |
510 | |
506 let i = 1 | 511 let i = 1 |
507 let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html") | 512 let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html") |
508 " Find an unused file name if current file name is already in use | 513 " Find an unused file name if current file name is already in use |
509 while filereadable(name) | 514 while filereadable(name) |
510 let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e") | 515 let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e") |
537 let style_start = search('^</head>')-1 | 542 let style_start = search('^</head>')-1 |
538 | 543 |
539 " add required javascript in reverse order so we can just call append again | 544 " add required javascript in reverse order so we can just call append again |
540 " and again without adjusting {{{ | 545 " and again without adjusting {{{ |
541 | 546 |
542 " insert script closing tag if any javascript is needed | 547 " insert script closing tag |
543 if s:settings.dynamic_folds || !empty(s:settings.prevent_copy) | 548 call append(style_start, [ |
544 call append(style_start, [ | 549 \ '', |
545 \ '', | 550 \ s:settings.use_xhtml ? '//]]>' : '-->', |
546 \ s:settings.use_xhtml ? '//]]>' : '-->', | 551 \ "</script>" |
547 \ "</script>" | 552 \ ]) |
548 \ ]) | |
549 endif | |
550 | 553 |
551 " insert script which corrects the size of small input elements in | 554 " insert script which corrects the size of small input elements in |
552 " prevent_copy mode. See 2html.vim for details on why this is needed and how | 555 " prevent_copy mode. See 2html.vim for details on why this is needed and how |
553 " it works. | 556 " it works. |
554 if !empty(s:settings.prevent_copy) | 557 if !empty(s:settings.prevent_copy) |
570 \ ' document.getElementById("vimCodeElement").className = "em"+ratio;', | 573 \ ' document.getElementById("vimCodeElement").className = "em"+ratio;', |
571 \ ' }', | 574 \ ' }', |
572 \ '}' | 575 \ '}' |
573 \ ]) | 576 \ ]) |
574 endif | 577 endif |
578 " | |
579 " insert javascript to get IDs from line numbers, and to open a fold before | |
580 " jumping to any lines contained therein | |
581 call append(style_start, [ | |
582 \ " /* Always jump to new location even if the line was hidden inside a fold, or", | |
583 \ " * we corrected the raw number to a line ID.", | |
584 \ " */", | |
585 \ " if (lineElem) {", | |
586 \ " lineElem.scrollIntoView(true);", | |
587 \ " }", | |
588 \ " return true;", | |
589 \ "}", | |
590 \ "if ('onhashchange' in window) {", | |
591 \ " window.onhashchange = JumpToLine;", | |
592 \ "}" | |
593 \ ]) | |
594 if s:settings.dynamic_folds | |
595 call append(style_start, [ | |
596 \ "", | |
597 \ " /* navigate upwards in the DOM tree to open all folds containing the line */", | |
598 \ " var node = lineElem;", | |
599 \ " while (node && node.id != 'vimCodeElement')", | |
600 \ " {", | |
601 \ " if (node.className == 'closed-fold')", | |
602 \ " {", | |
603 \ " /* toggle open the fold ID (remove window ID) */", | |
604 \ " toggleFold(node.id.substr(4));", | |
605 \ " }", | |
606 \ " node = node.parentNode;", | |
607 \ " }", | |
608 \ ]) | |
609 endif | |
610 call append(style_start, [ | |
611 \ "", | |
612 \ "/* function to open any folds containing a jumped-to line before jumping to it */", | |
613 \ "function JumpToLine()", | |
614 \ "{", | |
615 \ " var lineNum;", | |
616 \ " lineNum = window.location.hash;", | |
617 \ " lineNum = lineNum.substr(1); /* strip off '#' */", | |
618 \ "", | |
619 \ " if (lineNum.indexOf('L') == -1) {", | |
620 \ " lineNum = 'L'+lineNum;", | |
621 \ " }", | |
622 \ " if (lineNum.indexOf('W') == -1) {", | |
623 \ " lineNum = 'W1'+lineNum;", | |
624 \ " }", | |
625 \ " lineElem = document.getElementById(lineNum);" | |
626 \ ]) | |
575 | 627 |
576 " Insert javascript to toggle matching folds open and closed in all windows, | 628 " Insert javascript to toggle matching folds open and closed in all windows, |
577 " if dynamic folding is active. | 629 " if dynamic folding is active. |
578 if s:settings.dynamic_folds | 630 if s:settings.dynamic_folds |
579 call append(style_start, [ | 631 call append(style_start, [ |
594 \ " }", | 646 \ " }", |
595 \ " }", | 647 \ " }", |
596 \ ]) | 648 \ ]) |
597 endif | 649 endif |
598 | 650 |
599 " insert script tag if any javascript is needed | 651 " insert script tag; javascript is always needed for the line number |
600 if s:settings.dynamic_folds || s:settings.prevent_copy != "" | 652 " normalization for URL hashes |
601 call append(style_start, [ | 653 call append(style_start, [ |
602 \ "<script type='text/javascript'>", | 654 \ "<script type='text/javascript'>", |
603 \ s:settings.use_xhtml ? '//<![CDATA[' : "<!--"]) | 655 \ s:settings.use_xhtml ? '//<![CDATA[' : "<!--"]) |
604 endif "}}} | |
605 | 656 |
606 " Insert styles from all the generated html documents and additional styles | 657 " Insert styles from all the generated html documents and additional styles |
607 " for the table-based layout of the side-by-side diff. The diff should take | 658 " for the table-based layout of the side-by-side diff. The diff should take |
608 " up the full browser window (but not more), and be static in size, | 659 " up the full browser window (but not more), and be static in size, |
609 " horizontally scrollable when the lines are too long. Otherwise, the diff | 660 " horizontally scrollable when the lines are too long. Otherwise, the diff |