comparison runtime/syntax/2html.vim @ 2681:85c5a72551e2

Updated runtime files.
author Bram Moolenaar <bram@vim.org>
date Sat, 08 Jan 2011 16:06:37 +0100
parents 840c3cadb842
children 0877b8d6370e
comparison
equal deleted inserted replaced
2680:27621abffed2 2681:85c5a72551e2
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: 2010 Sep 04 3 " Last Change: 2011 Jan 06
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>
122 " separate the two classes by a space to apply them both if there is a diff 122 " separate the two classes by a space to apply them both if there is a diff
123 " style name 123 " style name
124 let l:style_name = a:style_name . (a:diff_style_name == '' ? '' : ' ') . a:diff_style_name 124 let l:style_name = a:style_name . (a:diff_style_name == '' ? '' : ' ') . a:diff_style_name
125 125
126 " Replace the reserved html characters 126 " Replace the reserved html characters
127 let formatted = substitute(substitute(substitute(substitute(substitute(formatted, '&', '\&amp;', 'g'), '<', '\&lt;', 'g'), '>', '\&gt;', 'g'), '"', '\&quot;', 'g'), "\x0c", '<hr class="PAGE-BREAK">', 'g') 127 let formatted = substitute(formatted, '&', '\&amp;', 'g')
128 let formatted = substitute(formatted, '<', '\&lt;', 'g')
129 let formatted = substitute(formatted, '>', '\&gt;', 'g')
130 let formatted = substitute(formatted, '"', '\&quot;', 'g')
131 " TODO: Use &apos; for "'"?
132
133 " Replace a "form feed" character with HTML to do a page break
134 let formatted = substitute(formatted, "\x0c", '<hr class="PAGE-BREAK">', 'g')
135
136 " Mangle modelines so Vim doesn't try to use HTML text as a modeline if
137 " editing this file in the future
138 let formatted = substitute(formatted, '\v(\s+%(vim?|ex)):', '\1\&#0058;', 'g')
128 139
129 " Replace double spaces, leading spaces, and trailing spaces if needed 140 " Replace double spaces, leading spaces, and trailing spaces if needed
130 if ' ' != s:HtmlSpace 141 if ' ' != s:HtmlSpace
131 let formatted = substitute(formatted, ' ', s:HtmlSpace . s:HtmlSpace, 'g') 142 let formatted = substitute(formatted, ' ', s:HtmlSpace . s:HtmlSpace, 'g')
132 let formatted = substitute(formatted, '^ ', s:HtmlSpace, 'g') 143 let formatted = substitute(formatted, '^ ', s:HtmlSpace, 'g')
556 if foldclosed(s:lnum) == s:lnum 567 if foldclosed(s:lnum) == s:lnum
557 " default fold text has '+-' and then a number of dashes equal to fold 568 " default fold text has '+-' and then a number of dashes equal to fold
558 " level, so subtract 2 from index of first non-dash after the dashes 569 " level, so subtract 2 from index of first non-dash after the dashes
559 " in order to get the fold level of the current fold 570 " in order to get the fold level of the current fold
560 let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2 571 let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
561 if s:level+1 > s:foldcolumn
562 let s:foldcolumn = s:level+1
563 endif
564 " store fold info for later use 572 " store fold info for later use
565 let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"} 573 let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
566 call add(s:allfolds, s:newfold) 574 call add(s:allfolds, s:newfold)
567 " open the fold so we can find any contained folds 575 " open the fold so we can find any contained folds
568 execute s:lnum."foldopen" 576 execute s:lnum."foldopen"
588 if foldclosed(s:lnum) == s:lnum 596 if foldclosed(s:lnum) == s:lnum
589 " default fold text has '+-' and then a number of dashes equal to fold 597 " default fold text has '+-' and then a number of dashes equal to fold
590 " level, so subtract 2 from index of first non-dash after the dashes 598 " level, so subtract 2 from index of first non-dash after the dashes
591 " in order to get the fold level of the current fold 599 " in order to get the fold level of the current fold
592 let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2 600 let s:level = match(foldtextresult(s:lnum), '+-*\zs[^-]') - 2
593 if s:level+1 > s:foldcolumn
594 let s:foldcolumn = s:level+1
595 endif
596 let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"} 601 let s:newfold = {'firstline': s:lnum, 'lastline': foldclosedend(s:lnum), 'level': s:level,'type': "closed-fold"}
597 " only add the fold if we don't already have it 602 " only add the fold if we don't already have it
598 if empty(s:allfolds) || index(s:allfolds, s:newfold) == -1 603 if empty(s:allfolds) || index(s:allfolds, s:newfold) == -1
599 let s:newfold.type = "open-fold" 604 let s:newfold.type = "open-fold"
600 call add(s:allfolds, s:newfold) 605 call add(s:allfolds, s:newfold)
620 let &l:foldtext = s:foldtext_save 625 let &l:foldtext = s:foldtext_save
621 unlet s:foldtext_save 626 unlet s:foldtext_save
622 627
623 " close all folds again so we can get the fold text as we go 628 " close all folds again so we can get the fold text as we go
624 silent! %foldclose! 629 silent! %foldclose!
630
631 for afold in s:allfolds
632 let removed = 0
633 if exists("g:html_start_line") && exists("g:html_end_line")
634 if afold.firstline < g:html_start_line
635 if afold.lastline < g:html_end_line && afold.lastline > g:html_start_line
636 " if a fold starts before the range to convert but stops within the
637 " range, we need to include it. Make it start on the first converted
638 " line.
639 let afold.firstline = g:html_start_line
640 else
641 " if the fold lies outside the range or the start and stop enclose
642 " the entire range, don't bother parsing it
643 call remove(s:allfolds, index(s:allfolds, afold))
644 let removed = 1
645 endif
646 elseif afold.firstline > g:html_end_line
647 " If the entire fold lies outside the range we need to remove it.
648 call remove(s:allfolds, index(s:allfolds, afold))
649 let removed = 1
650 endif
651 elseif exists("g:html_start_line")
652 if afold.firstline < g:html_start_line
653 " if there is no last line, but there is a first line, the end of the
654 " fold will always lie within the region of interest, so keep it
655 let afold.firstline = g:html_start_line
656 endif
657 elseif exists("g:html_end_line")
658 " if there is no first line we default to the first line in the buffer so
659 " the fold start will always be included if the fold itself is included.
660 " If however the entire fold lies outside the range we need to remove it.
661 if afold.firstline > g:html_end_line
662 call remove(s:allfolds, index(s:allfolds, afold))
663 let removed = 1
664 endif
665 endif
666 if !removed
667 if afold.level+1 > s:foldcolumn
668 let s:foldcolumn = afold.level+1
669 endif
670 endif
671 endfor
625 endif 672 endif
626 673
627 " Now loop over all lines in the original text to convert to html. 674 " Now loop over all lines in the original text to convert to html.
628 " Use html_start_line and html_end_line if they are set. 675 " Use html_start_line and html_end_line if they are set.
629 if exists("g:html_start_line") 676 if exists("g:html_start_line")
666 if s:difffillchar == '' 713 if s:difffillchar == ''
667 let s:difffillchar = '-' 714 let s:difffillchar = '-'
668 endif 715 endif
669 716
670 let s:foldId = 0 717 let s:foldId = 0
718
719 if !s:settings.expand_tabs
720 " If keeping tabs, add them to printable characters so we keep them when
721 " formatting text (strtrans() doesn't replace printable chars)
722 let s:old_isprint = &isprint
723 setlocal isprint+=9
724 endif
671 725
672 while s:lnum <= s:end 726 while s:lnum <= s:end
673 727
674 " If there are filler lines for diff mode, show these above the line. 728 " If there are filler lines for diff mode, show these above the line.
675 let s:filler = diff_filler(s:lnum) 729 let s:filler = diff_filler(s:lnum)
745 while !empty(s:foldstack) && get(s:foldstack,0).lastline == s:lnum-1 799 while !empty(s:foldstack) && get(s:foldstack,0).lastline == s:lnum-1
746 let s:new = s:new."</span></span>" 800 let s:new = s:new."</span></span>"
747 call remove(s:foldstack, 0) 801 call remove(s:foldstack, 0)
748 endwhile 802 endwhile
749 803
750 " Now insert an opening any new folds that start on this line 804 " Now insert an opening for any new folds that start on this line
751 let s:firstfold = 1 805 let s:firstfold = 1
752 while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum 806 while !empty(s:allfolds) && get(s:allfolds,0).firstline == s:lnum
753 let s:foldId = s:foldId + 1 807 let s:foldId = s:foldId + 1
754 let s:new .= "<span id='" 808 let s:new .= "<span id='"
755 let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "") 809 let s:new .= (exists('g:html_diff_win_num') ? "win".g:html_diff_win_num : "")
882 " Go along till we find a change in synID 936 " Go along till we find a change in synID
883 while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile 937 while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
884 endif 938 endif
885 939
886 if s:settings.ignore_conceal || !s:concealinfo[0] 940 if s:settings.ignore_conceal || !s:concealinfo[0]
887 " Expand tabs 941 " Expand tabs if needed
888 let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol) 942 let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol)
889 let s:offset = 0 943 if s:settings.expand_tabs
890 let s:idx = stridx(s:expandedtab, "\t") 944 let s:offset = 0
891 while s:idx >= 0 945 let s:idx = stridx(s:expandedtab, "\t")
892 if has("multi_byte_encoding") 946 while s:idx >= 0
893 if s:startcol + s:idx == 1 947 if has("multi_byte_encoding")
894 let s:i = &ts 948 if s:startcol + s:idx == 1
949 let s:i = &ts
950 else
951 if s:idx == 0
952 let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c')
953 else
954 let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c')
955 endif
956 let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)])
957 let s:i = &ts - (s:vcol % &ts)
958 endif
959 let s:offset -= s:i - 1
895 else 960 else
896 if s:idx == 0 961 let s:i = &ts - ((s:idx + s:startcol - 1) % &ts)
897 let s:prevc = matchstr(s:line, '.\%' . (s:startcol + s:idx + s:offset) . 'c')
898 else
899 let s:prevc = matchstr(s:expandedtab, '.\%' . (s:idx + 1) . 'c')
900 endif
901 let s:vcol = virtcol([s:lnum, s:startcol + s:idx + s:offset - len(s:prevc)])
902 let s:i = &ts - (s:vcol % &ts)
903 endif 962 endif
904 let s:offset -= s:i - 1 963 let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '')
905 else 964 let s:idx = stridx(s:expandedtab, "\t")
906 let s:i = &ts - ((s:idx + s:startcol - 1) % &ts) 965 endwhile
907 endif 966 end
908 let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', s:i), '')
909 let s:idx = stridx(s:expandedtab, "\t")
910 endwhile
911 967
912 " get the highlight group name to use 968 " get the highlight group name to use
913 let s:id = synIDtrans(s:id) 969 let s:id = synIDtrans(s:id)
914 let s:id_name = synIDattr(s:id, "name", s:whatterm) 970 let s:id_name = synIDattr(s:id, "name", s:whatterm)
915 if s:diff_id 971 if s:diff_id
1071 endif 1127 endif
1072 1128
1073 " Cleanup 1129 " Cleanup
1074 %s:\s\+$::e 1130 %s:\s\+$::e
1075 1131
1076 " Restore old settings 1132 " Restore old settings (new window first)
1077 let &l:foldenable = s:old_fen 1133 let &l:foldenable = s:old_fen
1078 let &l:foldmethod = s:old_fdm 1134 let &l:foldmethod = s:old_fdm
1079 let &report = s:old_report 1135 let &report = s:old_report
1080 let &title = s:old_title 1136 let &title = s:old_title
1081 let &icon = s:old_icon 1137 let &icon = s:old_icon
1082 let &paste = s:old_paste 1138 let &paste = s:old_paste
1083 let &magic = s:old_magic 1139 let &magic = s:old_magic
1084 let @/ = s:old_search 1140 let @/ = s:old_search
1085 let &more = s:old_more 1141 let &more = s:old_more
1142
1143 " switch to original window to restore those settings
1086 exe s:orgwin . "wincmd w" 1144 exe s:orgwin . "wincmd w"
1145
1146 if !s:settings.expand_tabs
1147 let &l:isprint = s:old_isprint
1148 endif
1087 let &l:stl = s:origwin_stl 1149 let &l:stl = s:origwin_stl
1088 let &l:et = s:old_et 1150 let &l:et = s:old_et
1089 let &l:scrollbind = s:old_bind 1151 let &l:scrollbind = s:old_bind
1152
1153 " and back to the new window again to end there
1090 exe s:newwin . "wincmd w" 1154 exe s:newwin . "wincmd w"
1155
1091 let &l:stl = s:newwin_stl 1156 let &l:stl = s:newwin_stl
1092 exec 'resize' s:old_winheight 1157 exec 'resize' s:old_winheight
1093 let &l:winfixheight = s:old_winfixheight 1158 let &l:winfixheight = s:old_winfixheight
1094 1159
1095 let &ls=s:ls 1160 let &ls=s:ls
1096 1161
1097 " Save a little bit of memory (worth doing?) 1162 " Save a little bit of memory (worth doing?)
1098 unlet s:htmlfont 1163 unlet s:htmlfont
1099 unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search 1164 unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search
1100 unlet s:old_magic s:old_more s:old_fdm s:old_fen s:old_winheight 1165 unlet s:old_magic s:old_more s:old_fdm s:old_fen s:old_winheight
1166 unlet! s:old_isprint
1101 unlet s:whatterm s:idlist s:lnum s:end s:margin s:fgc s:bgc s:old_winfixheight 1167 unlet s:whatterm s:idlist s:lnum s:end s:margin s:fgc s:bgc s:old_winfixheight
1102 unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:concealinfo 1168 unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:concealinfo
1103 unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset s:ls s:origwin_stl 1169 unlet! s:orgwin s:newwin s:orgbufnr s:idx s:i s:offset s:ls s:origwin_stl
1104 unlet! s:newwin_stl s:current_syntax 1170 unlet! s:newwin_stl s:current_syntax
1105 if !v:profiling 1171 if !v:profiling