annotate runtime/syntax/2html.vim @ 844:d3bbb5dd3913 v7.0f02

updated for version 7.0f02
author vimboss
date Thu, 27 Apr 2006 00:02:13 +0000
parents 6bb1fa855dc9
children 8cd729851562
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
1 " Vim syntax support file
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
2 " Maintainer: Bram Moolenaar <Bram@vim.org>
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
3 " Last Change: 2006 Apr 19
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
4 " (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
5 " (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
6
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
7 " Transform a file into HTML, using the current syntax highlighting.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
9 " Number lines when explicitely requested or when `number' is set
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
10 if exists("html_number_lines")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
11 let s:numblines = html_number_lines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
12 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
13 let s:numblines = &number
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
14 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
15
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
16 " When not in gui we can only guess the colors.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
17 if has("gui_running")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
18 let s:whatterm = "gui"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
19 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
20 let s:whatterm = "cterm"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
21 if &t_Co == 8
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
22 let s:cterm_color0 = "#808080"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
23 let s:cterm_color1 = "#ff6060"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
24 let s:cterm_color2 = "#00ff00"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
25 let s:cterm_color3 = "#ffff00"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
26 let s:cterm_color4 = "#8080ff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
27 let s:cterm_color5 = "#ff40ff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
28 let s:cterm_color6 = "#00ffff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
29 let s:cterm_color7 = "#ffffff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
30 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
31 let s:cterm_color0 = "#000000"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
32 let s:cterm_color1 = "#c00000"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
33 let s:cterm_color2 = "#008000"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
34 let s:cterm_color3 = "#804000"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
35 let s:cterm_color4 = "#0000c0"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
36 let s:cterm_color5 = "#c000c0"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
37 let s:cterm_color6 = "#008080"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
38 let s:cterm_color7 = "#c0c0c0"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
39 let s:cterm_color8 = "#808080"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
40 let s:cterm_color9 = "#ff6060"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
41 let s:cterm_color10 = "#00ff00"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
42 let s:cterm_color11 = "#ffff00"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
43 let s:cterm_color12 = "#8080ff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
44 let s:cterm_color13 = "#ff40ff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
45 let s:cterm_color14 = "#00ffff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
46 let s:cterm_color15 = "#ffffff"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
47 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
48 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
49
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
50 " Return good color specification: in GUI no transformation is done, in
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
51 " terminal return RGB values of known colors and empty string on unknown
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
52 if s:whatterm == "gui"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
53 function! s:HtmlColor(color)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
54 return a:color
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
55 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
56 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
57 function! s:HtmlColor(color)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
58 if exists("s:cterm_color" . a:color)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
59 execute "return s:cterm_color" . a:color
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
60 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
61 return ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
62 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
63 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
64 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
65
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
66 if !exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
67 " Return opening HTML tag for given highlight id
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
68 function! s:HtmlOpening(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
69 let a = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
70 if synIDattr(a:id, "inverse")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
71 " For inverse, we always must set both colors (and exchange them)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
72 let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
73 let a = a . '<span style="background-color: ' . ( x != "" ? x : s:fgc ) . '">'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
74 let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
75 let a = a . '<font color="' . ( x != "" ? x : s:bgc ) . '">'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
76 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
77 let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
78 if x != "" | let a = a . '<span style="background-color: ' . x . '">' | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
79 let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
80 if x != "" | let a = a . '<font color="' . x . '">' | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
81 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
82 if synIDattr(a:id, "bold") | let a = a . "<b>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
83 if synIDattr(a:id, "italic") | let a = a . "<i>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
84 if synIDattr(a:id, "underline") | let a = a . "<u>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
85 return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
86 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
87
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
88 " Return closing HTML tag for given highlight id
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
89 function s:HtmlClosing(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
90 let a = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
91 if synIDattr(a:id, "underline") | let a = a . "</u>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
92 if synIDattr(a:id, "italic") | let a = a . "</i>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
93 if synIDattr(a:id, "bold") | let a = a . "</b>" | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
94 if synIDattr(a:id, "inverse")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
95 let a = a . '</font></span>'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
96 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
97 let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
98 if x != "" | let a = a . '</font>' | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
99 let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
100 if x != "" | let a = a . '</span>' | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
101 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
102 return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
103 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
104 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
105
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
106 " Return HTML valid characters enclosed in a span of class style_name with
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
107 " unprintable characters expanded and double spaces replaced as necessary.
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
108 function! s:HtmlFormat(text, style_name)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
109 " Replace unprintable characters
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
110 let formatted = strtrans(a:text)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
111
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
112 " Replace the reserved html characters
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
113 let formatted = substitute(substitute(substitute(substitute(substitute(formatted, '&', '\&amp;', 'g'), '<', '\&lt;', 'g'), '>', '\&gt;', 'g'), '"', '\&quot;', 'g'), "\x0c", '<hr class="PAGE-BREAK">', 'g')
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
114
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
115 " Replace double spaces and leading spaces
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
116 if ' ' != s:HtmlSpace
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
117 let formatted = substitute(formatted, ' ', s:HtmlSpace . s:HtmlSpace, 'g')
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
118 let formatted = substitute(formatted, '^ ', s:HtmlSpace, 'g')
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
119 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
120
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
121 " Enclose in a span of class style_name
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
122 let formatted = '<span class="' . a:style_name . '">' . formatted . '</span>'
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
123
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
124 " Add the class to class list if it's not there yet
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
125 let s:id = hlID(a:style_name)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
126 if stridx(s:idlist, "," . s:id . ",") == -1
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
127 let s:idlist = s:idlist . s:id . ","
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
128 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
129
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
130 return formatted
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
131 endfun
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
132
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
133 " Return CSS style describing given highlight id (can be empty)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
134 function! s:CSS1(id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
135 let a = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
136 if synIDattr(a:id, "inverse")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
137 " For inverse, we always must set both colors (and exchange them)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
138 let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
139 let a = a . "color: " . ( x != "" ? x : s:bgc ) . "; "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
140 let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
141 let a = a . "background-color: " . ( x != "" ? x : s:fgc ) . "; "
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
142 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
143 let x = s:HtmlColor(synIDattr(a:id, "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
144 if x != "" | let a = a . "color: " . x . "; " | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
145 let x = s:HtmlColor(synIDattr(a:id, "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
146 if x != "" | let a = a . "background-color: " . x . "; " | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
147 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
148 if synIDattr(a:id, "bold") | let a = a . "font-weight: bold; " | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
149 if synIDattr(a:id, "italic") | let a = a . "font-style: italic; " | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
150 if synIDattr(a:id, "underline") | let a = a . "text-decoration: underline; " | endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
151 return a
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
152 endfun
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
153
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
154 " Figure out proper MIME charset from the 'encoding' option.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
155 if exists("html_use_encoding")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
156 let s:html_encoding = html_use_encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
157 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
158 let s:vim_encoding = &encoding
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
159 if s:vim_encoding =~ '^8bit\|^2byte'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
160 let s:vim_encoding = substitute(s:vim_encoding, '^8bit-\|^2byte-', '', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
161 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
162 if s:vim_encoding == 'latin1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
163 let s:html_encoding = 'iso-8859-1'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
164 elseif s:vim_encoding =~ "^cp12"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
165 let s:html_encoding = substitute(s:vim_encoding, 'cp', 'windows-', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
166 elseif s:vim_encoding == 'sjis'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
167 let s:html_encoding = 'Shift_JIS'
575
f1d46f948241 updated for version 7.0163
vimboss
parents: 572
diff changeset
168 elseif s:vim_encoding == 'big5'
f1d46f948241 updated for version 7.0163
vimboss
parents: 572
diff changeset
169 let s:html_encoding = "Big5"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
170 elseif s:vim_encoding == 'euc-cn'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
171 let s:html_encoding = 'GB_2312-80'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
172 elseif s:vim_encoding == 'euc-tw'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
173 let s:html_encoding = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
174 elseif s:vim_encoding =~ '^euc\|^iso\|^koi'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
175 let s:html_encoding = substitute(s:vim_encoding, '.*', '\U\0', '')
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
176 elseif s:vim_encoding == 'cp949'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
177 let s:html_encoding = 'KS_C_5601-1987'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
178 elseif s:vim_encoding == 'cp936'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
179 let s:html_encoding = 'GBK'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
180 elseif s:vim_encoding =~ '^ucs\|^utf'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
181 let s:html_encoding = 'UTF-8'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
182 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
183 let s:html_encoding = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
184 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
185 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
186
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
187
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
188 " Set some options to make it work faster.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
189 " Don't report changes for :substitute, there will be many of them.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
190 let s:old_title = &title
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
191 let s:old_icon = &icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
192 let s:old_et = &l:et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
193 let s:old_report = &report
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
194 let s:old_search = @/
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
195 set notitle noicon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
196 setlocal et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
197 set report=1000000
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
198
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
199 " Split window to create a buffer with the HTML file.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
200 let s:orgbufnr = winbufnr(0)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
201 if expand("%") == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
202 new Untitled.html
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
203 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
204 new %.html
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
205 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
206 let s:newwin = winnr()
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
207 let s:orgwin = bufwinnr(s:orgbufnr)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
208
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
209 set modifiable
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
210 %d
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
211 let s:old_paste = &paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
212 set paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
213 let s:old_magic = &magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
214 set magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
215
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
216 if exists("use_xhtml")
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
217 if s:html_encoding != ""
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
218 exe "normal! a<?xml version=\"1.0\" encoding=\"" . s:html_encoding . "\"?>\n\e"
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
219 else
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
220 exe "normal! a<?xml version=\"1.0\"?>\n\e"
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
221 endif
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
222 let s:tag_close = '/>'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
223 else
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
224 let s:tag_close = '>'
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
225 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
226
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
227 let s:HtmlSpace = ' '
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
228 let s:LeadingSpace = ' '
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
229 let s:HtmlEndline = ''
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
230 if exists("html_no_pre")
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
231 let s:HtmlEndline = '<br' . s:tag_close
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
232 if exists("use_xhtml")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
233 let s:LeadingSpace = '&#x20;'
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
234 else
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
235 let s:LeadingSpace = '&nbsp;'
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
236 endif
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
237 let s:HtmlSpace = '\' . s:LeadingSpace
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
238 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
239
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
240 " HTML header, with the title and generator ;-). Left free space for the CSS,
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
241 " to be filled at the end.
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
242 exe "normal! a<html>\n\e"
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
243 exe "normal! a<head>\n<title>" . expand("%:p:~") . "</title>\n\e"
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
244 exe "normal! a<meta name=\"Generator\" content=\"Vim/" . v:version/100 . "." . v:version %100 . '"' . s:tag_close . "\n\e"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
245 if s:html_encoding != ""
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
246 exe "normal! a<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:html_encoding . '"' . s:tag_close . "\n\e"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
247 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
248 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
249 exe "normal! a<style type=\"text/css\">\n<!--\n-->\n</style>\n\e"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
250 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
251 if exists("html_no_pre")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
252 if exists("use_xhtml")
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
253 exe "normal! a</head>\n<body>\n<p>\n\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
254 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
255 exe "normal! a</head>\n<body>\n\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
256 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
257 else
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
258 if exists("use_xhtml")
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
259 exe "normal! a</head>\n<body>\n<p>\n<pre>\n\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
260 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
261 exe "normal! a</head>\n<body>\n<pre>\n\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
262 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
263 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
264
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
265 exe s:orgwin . "wincmd w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
266
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
267 " List of all id's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
268 let s:idlist = ","
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
269
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
270 " Loop over all lines in the original text.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
271 " Use html_start_line and html_end_line if they are set.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
272 if exists("html_start_line")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
273 let s:lnum = html_start_line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
274 if s:lnum < 1 || s:lnum > line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
275 let s:lnum = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
276 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
277 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
278 let s:lnum = 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
279 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
280 if exists("html_end_line")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
281 let s:end = html_end_line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
282 if s:end < s:lnum || s:end > line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
283 let s:end = line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
284 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
285 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
286 let s:end = line("$")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
287 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
288
279
946f0cbdd535 updated for version 7.0074
vimboss
parents: 170
diff changeset
289 if has('folding') && !exists('html_ignore_folding')
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
290 let s:foldfillchar = &fillchars[matchend(&fillchars, 'fold:')]
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
291 if s:foldfillchar == ''
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
292 let s:foldfillchar = '-'
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
293 endif
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
294 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
295 let s:difffillchar = &fillchars[matchend(&fillchars, 'diff:')]
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
296 if s:difffillchar == ''
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
297 let s:difffillchar = '-'
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
298 endif
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
299
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
300
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
301 while s:lnum <= s:end
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
302
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
303 " If there are filler lines for diff mode, show these above the line.
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
304 let s:filler = diff_filler(s:lnum)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
305 if s:filler > 0
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
306 let s:n = s:filler
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
307 while s:n > 0
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
308 if s:numblines
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
309 " Indent if line numbering is on
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
310 let s:new = repeat(s:LeadingSpace, strlen(s:end) + 1) . repeat(s:difffillchar, 3)
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
311 else
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
312 let s:new = repeat(s:difffillchar, 3)
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
313 endif
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
314
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
315 if s:n > 2 && s:n < s:filler && !exists("html_whole_filler")
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
316 let s:new = s:new . " " . s:filler . " inserted lines "
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
317 let s:n = 2
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
318 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
319
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
320 if !exists("html_no_pre")
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
321 " HTML line wrapping is off--go ahead and fill to the margin
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
322 let s:new = s:new . repeat(s:difffillchar, &columns - strlen(s:new))
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
323 endif
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
324
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
325 let s:new = s:HtmlFormat(s:new, "DiffDelete")
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
326 exe s:newwin . "wincmd w"
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
327 exe "normal! a" . s:new . s:HtmlEndline . "\n\e"
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
328 exe s:orgwin . "wincmd w"
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
329
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
330 let s:n = s:n - 1
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
331 endwhile
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
332 unlet s:n
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
333 endif
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
334 unlet s:filler
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
335
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
336 " Start the line with the line number.
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
337 if s:numblines
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
338 let s:new = repeat(' ', strlen(s:end) - strlen(s:lnum)) . s:lnum . ' '
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
339 else
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
340 let s:new = ""
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
341 endif
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
342
279
946f0cbdd535 updated for version 7.0074
vimboss
parents: 170
diff changeset
343 if has('folding') && !exists('html_ignore_folding') && foldclosed(s:lnum) > -1
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
344 "
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
345 " This is the beginning of a folded block
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
346 "
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
347 let s:new = s:new . foldtextresult(s:lnum)
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
348 if !exists("html_no_pre")
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
349 " HTML line wrapping is off--go ahead and fill to the margin
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
350 let s:new = s:new . repeat(s:foldfillchar, &columns - strlen(s:new))
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
351 endif
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
352
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
353 let s:new = s:HtmlFormat(s:new, "Folded")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
354
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
355 " Skip to the end of the fold
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
356 let s:lnum = foldclosedend(s:lnum)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
357
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
358 else
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
359 "
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
360 " A line that is not folded.
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
361 "
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
362 let s:line = getline(s:lnum)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
363
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
364 let s:len = strlen(s:line)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
365
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
366 if s:numblines
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
367 let s:new = s:HtmlFormat(s:new, "lnr")
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
368 endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
369
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
370 " Get the diff attribute, if any.
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
371 let s:diffattr = diff_hlID(s:lnum, 1)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
372
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
373 " Loop over each character in the line
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
374 let s:col = 1
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
375 while s:col <= s:len || (s:col == 1 && s:diffattr)
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
376 let s:startcol = s:col " The start column for processing text
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
377 if s:diffattr
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
378 let s:id = diff_hlID(s:lnum, s:col)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
379 let s:col = s:col + 1
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
380 " Speed loop (it's small - that's the trick)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
381 " Go along till we find a change in hlID
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
382 while s:col <= s:len && s:id == diff_hlID(s:lnum, s:col) | let s:col = s:col + 1 | endwhile
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
383 if s:len < &columns && !exists("html_no_pre")
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
384 " Add spaces at the end to mark the changed line.
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
385 let s:line = s:line . repeat(' ', &columns - s:len)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
386 let s:len = &columns
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
387 endif
32
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
388 else
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
389 let s:id = synID(s:lnum, s:col, 1)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
390 let s:col = s:col + 1
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
391 " Speed loop (it's small - that's the trick)
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
392 " Go along till we find a change in synID
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
393 while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
41f9fd58cf13 updated for version 7.0019
vimboss
parents: 29
diff changeset
394 endif
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
395
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
396 " Expand tabs
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
397 let s:expandedtab = strpart(s:line, s:startcol - 1, s:col - s:startcol)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
398 let idx = stridx(s:expandedtab, "\t")
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
399 while idx >= 0
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
400 let i = &ts - ((idx + s:startcol - 1) % &ts)
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
401 let s:expandedtab = substitute(s:expandedtab, '\t', repeat(' ', i), '')
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
402 let idx = stridx(s:expandedtab, "\t")
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
403 endwhile
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
404
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
405 " Output the text with the same synID, with class set to {s:id_name}
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
406 let s:id = synIDtrans(s:id)
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
407 let s:id_name = synIDattr(s:id, "name", s:whatterm)
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
408 let s:new = s:new . s:HtmlFormat(s:expandedtab, s:id_name)
29
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
409 endwhile
ac33b7c03fac updated for version 7.0018
vimboss
parents: 7
diff changeset
410 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
411
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
412 exe s:newwin . "wincmd w"
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
413 exe "normal! a" . s:new . s:HtmlEndline . "\n\e"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
414 exe s:orgwin . "wincmd w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
415 let s:lnum = s:lnum + 1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
416 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
417 " Finish with the last line
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
418 exe s:newwin . "wincmd w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
419 if exists("html_no_pre")
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
420 if exists("use_xhtml")
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
421 exe "normal! a</p>\n</body>\n</html>\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
422 else
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
423 exe "normal! a</body>\n</html>\e"
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
424 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
425 else
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
426 if exists("use_xhtml")
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
427 exe "normal! a</pre>\n</p>\n</body>\n</html>\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
428 else
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
429 exe "normal! a</pre>\n</body>\n</html>\e"
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
430 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
431 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
432
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
433
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
434 " Now, when we finally know which, we define the colors and styles
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
435 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
436 1;/<style type="text/+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
437 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
438
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
439 " Find out the background and foreground color.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
440 let s:fgc = s:HtmlColor(synIDattr(hlID("Normal"), "fg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
441 let s:bgc = s:HtmlColor(synIDattr(hlID("Normal"), "bg#", s:whatterm))
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
442 if s:fgc == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
443 let s:fgc = ( &background == "dark" ? "#ffffff" : "#000000" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
444 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
445 if s:bgc == ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
446 let s:bgc = ( &background == "dark" ? "#000000" : "#ffffff" )
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
447 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
448
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
449 " Normal/global attributes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
450 " For Netscape 4, set <body> attributes too, though, strictly speaking, it's
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
451 " incorrect.
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
452 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
453 if exists("html_no_pre")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
454 execute "normal! A\nbody { color: " . s:fgc . "; background-color: " . s:bgc . "; font-family: Courier, monospace; }\e"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
455 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
456 execute "normal! A\npre { color: " . s:fgc . "; background-color: " . s:bgc . "; }\e"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
457 yank
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
458 put
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
459 execute "normal! ^cwbody\e"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
460 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
461 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
462 if exists("html_no_pre")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
463 execute '%s:<body>:<body ' . 'bgcolor="' . s:bgc . '" text="' . s:fgc . '" style="font-family\: Courier, monospace;">'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
464 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
465 execute '%s:<body>:<body ' . 'bgcolor="' . s:bgc . '" text="' . s:fgc . '">'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
466 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
467 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
468
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
469 " Line numbering attributes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
470 if s:numblines
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
471 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
472 execute "normal! A\n.lnr { " . s:CSS1(hlID("LineNr")) . "}\e"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
473 else
837
6bb1fa855dc9 updated for version 7.0e03
vimboss
parents: 836
diff changeset
474 execute '%s+^<span class="lnr">\([^<]*\)</span>+' . s:HtmlOpening(hlID("LineNr")) . '\1' . s:HtmlClosing(hlID("LineNr")) . '+g'
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
475 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
476 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
477
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
478 " Gather attributes for all other classes
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
479 let s:idlist = strpart(s:idlist, 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
480 while s:idlist != ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
481 let s:attr = ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
482 let s:col = stridx(s:idlist, ",")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
483 let s:id = strpart(s:idlist, 0, s:col)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
484 let s:idlist = strpart(s:idlist, s:col + 1)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
485 let s:attr = s:CSS1(s:id)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
486 let s:id_name = synIDattr(s:id, "name", s:whatterm)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
487 " If the class has some attributes, export the style, otherwise DELETE all
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
488 " its occurences to make the HTML shorter
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
489 if s:attr != ""
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
490 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
491 execute "normal! A\n." . s:id_name . " { " . s:attr . "}"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
492 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
493 execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+' . s:HtmlOpening(s:id) . '\1' . s:HtmlClosing(s:id) . '+g'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
494 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
495 else
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
496 execute '%s+<span class="' . s:id_name . '">\([^<]*\)</span>+\1+g'
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
497 if exists("html_use_css")
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
498 1;/<style type="text/+1
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
499 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
500 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
501 endwhile
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
502
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
503 " Add hyperlinks
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
504 %s+\(https\=://\S\{-}\)\(\([.,;:}]\=\(\s\|$\)\)\|[\\"'<>]\|&gt;\|&lt;\|&quot;\)+<a href="\1">\1</a>\2+ge
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
505
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
506 " The DTD
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
507 if exists("html_use_css")
39
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
508 if exists("use_xhtml")
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
509 exe "normal! gg$a\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\e"
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
510 else
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
511 exe "normal! gg0i<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n\e"
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
512 endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
513 endif
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
514
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
515 if exists("use_xhtml")
410fa1a31baf updated for version 7.0023
vimboss
parents: 34
diff changeset
516 exe "normal! gg/<html/e\na xmlns=\"http://www.w3.org/1999/xhtml\"\e"
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
517 endif
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
518
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
519 " Cleanup
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
520 %s:\s\+$::e
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
521
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
522 " Restore old settings
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
523 let &report = s:old_report
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
524 let &title = s:old_title
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
525 let &icon = s:old_icon
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
526 let &paste = s:old_paste
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
527 let &magic = s:old_magic
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
528 let @/ = s:old_search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
529 exe s:orgwin . "wincmd w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
530 let &l:et = s:old_et
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
531 exe s:newwin . "wincmd w"
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
532
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
533 " Save a little bit of memory (worth doing?)
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
534 unlet s:old_et s:old_paste s:old_icon s:old_report s:old_title s:old_search
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
535 unlet s:whatterm s:idlist s:lnum s:end s:fgc s:bgc s:old_magic
34
7f788cd27415 updated for version 7.0020
vimboss
parents: 32
diff changeset
536 unlet! s:col s:id s:attr s:len s:line s:new s:expandedtab s:numblines
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
537 unlet s:orgwin s:newwin s:orgbufnr
170
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
538 if !v:profiling
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
539 delfunc s:HtmlColor
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
540 delfunc s:HtmlFormat
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
541 delfunc s:CSS1
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
542 if !exists("html_use_css")
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
543 delfunc s:HtmlOpening
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
544 delfunc s:HtmlClosing
8c60f65311fa updated for version 7.0052
vimboss
parents: 39
diff changeset
545 endif
7
3fc0f57ecb91 updated for version 7.0001
vimboss
parents:
diff changeset
546 endif
836
5a7843c57316 updated for version 7.0e02
vimboss
parents: 575
diff changeset
547 silent! unlet s:diffattr s:difffillchar s:foldfillchar s:HtmlSpace s:LeadingSpace s:HtmlEndline