Mercurial > vim
annotate runtime/autoload/tohtml.vim @ 3376:1632640a24b4 v7.3.454
updated for version 7.3.454
Problem: Re-allocating memory slows Vim down.
Solution: Use realloc() in ga_grow(). (Dominique Pelle)
author | Bram Moolenaar <bram@vim.org> |
---|---|
date | Wed, 22 Feb 2012 18:12:32 +0100 |
parents | 0877b8d6370e |
children | 9910cbff5f16 |
rev | line source |
---|---|
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
1 " Vim autoload file for the tohtml plugin. |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
2 " Maintainer: Ben Fritz <fritzophrenic@gmail.com> |
2788 | 3 " Last Change: 2011 Apr 05 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
4 " |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
5 " Additional contributors: |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
6 " |
2334
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
7 " Original by Bram Moolenaar <Bram@vim.org> |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
8 " Diff2HTML() added by Christian Brabandt <cb@256bit.org> |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
9 " |
2334
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
10 " See Mercurial change logs for more! |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
11 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
12 " this file uses line continuations |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
13 let s:cpo_sav = &cpo |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
14 set cpo-=C |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
15 |
2642 | 16 " Automatically find charsets from all encodings supported natively by Vim. With |
17 " the 8bit- and 2byte- prefixes, Vim can actually support more encodings than | |
18 " this. Let the user specify these however since they won't be supported on | |
2788 | 19 " every system. |
2642 | 20 " |
21 " Note, not all of Vim's supported encodings have a charset to use. | |
22 " | |
23 " Names in this list are from: | |
24 " http://www.iana.org/assignments/character-sets | |
25 " g:tohtml#encoding_to_charset: {{{ | |
26 let g:tohtml#encoding_to_charset = { | |
27 \ 'latin1' : 'ISO-8859-1', | |
28 \ 'iso-8859-2' : 'ISO-8859-2', | |
29 \ 'iso-8859-3' : 'ISO-8859-3', | |
30 \ 'iso-8859-4' : 'ISO-8859-4', | |
31 \ 'iso-8859-5' : 'ISO-8859-5', | |
32 \ 'iso-8859-6' : 'ISO-8859-6', | |
33 \ 'iso-8859-7' : 'ISO-8859-7', | |
34 \ 'iso-8859-8' : 'ISO-8859-8', | |
35 \ 'iso-8859-9' : 'ISO-8859-9', | |
36 \ 'iso-8859-10' : '', | |
37 \ 'iso-8859-13' : 'ISO-8859-13', | |
38 \ 'iso-8859-14' : '', | |
39 \ 'iso-8859-15' : 'ISO-8859-15', | |
40 \ 'koi8-r' : 'KOI8-R', | |
41 \ 'koi8-u' : 'KOI8-U', | |
42 \ 'macroman' : 'macintosh', | |
43 \ 'cp437' : '', | |
44 \ 'cp775' : '', | |
45 \ 'cp850' : '', | |
46 \ 'cp852' : '', | |
47 \ 'cp855' : '', | |
48 \ 'cp857' : '', | |
49 \ 'cp860' : '', | |
50 \ 'cp861' : '', | |
51 \ 'cp862' : '', | |
52 \ 'cp863' : '', | |
53 \ 'cp865' : '', | |
54 \ 'cp866' : 'IBM866', | |
55 \ 'cp869' : '', | |
56 \ 'cp874' : '', | |
57 \ 'cp1250' : 'windows-1250', | |
58 \ 'cp1251' : 'windows-1251', | |
59 \ 'cp1253' : 'windows-1253', | |
60 \ 'cp1254' : 'windows-1254', | |
61 \ 'cp1255' : 'windows-1255', | |
62 \ 'cp1256' : 'windows-1256', | |
63 \ 'cp1257' : 'windows-1257', | |
64 \ 'cp1258' : 'windows-1258', | |
65 \ 'euc-jp' : 'EUC-JP', | |
66 \ 'sjis' : 'Shift_JIS', | |
67 \ 'cp932' : 'Shift_JIS', | |
68 \ 'cp949' : '', | |
69 \ 'euc-kr' : 'EUC-KR', | |
70 \ 'cp936' : 'GBK', | |
71 \ 'euc-cn' : 'GB2312', | |
72 \ 'big5' : 'Big5', | |
73 \ 'cp950' : 'Big5', | |
74 \ 'utf-8' : 'UTF-8', | |
75 \ 'ucs-2' : 'UTF-8', | |
76 \ 'ucs-2le' : 'UTF-8', | |
77 \ 'utf-16' : 'UTF-8', | |
78 \ 'utf-16le' : 'UTF-8', | |
79 \ 'ucs-4' : 'UTF-8', | |
80 \ 'ucs-4le' : 'UTF-8', | |
81 \ } | |
82 lockvar g:tohtml#encoding_to_charset | |
83 " Notes: | |
84 " 1. All UCS/UTF are converted to UTF-8 because it is much better supported | |
85 " 2. Any blank spaces are there because Vim supports it but at least one major | |
86 " web browser does not according to http://wiki.whatwg.org/wiki/Web_Encodings. | |
87 " }}} | |
88 | |
89 " Only automatically find encodings supported natively by Vim, let the user | |
90 " specify the encoding if it's not natively supported. This function is only | |
91 " used when the user specifies the charset, they better know what they are | |
92 " doing! | |
93 " | |
94 " Names in this list are from: | |
95 " http://www.iana.org/assignments/character-sets | |
96 " g:tohtml#charset_to_encoding: {{{ | |
97 let g:tohtml#charset_to_encoding = { | |
98 \ 'iso_8859-1:1987' : 'latin1', | |
99 \ 'iso-ir-100' : 'latin1', | |
100 \ 'iso_8859-1' : 'latin1', | |
101 \ 'iso-8859-1' : 'latin1', | |
102 \ 'latin1' : 'latin1', | |
103 \ 'l1' : 'latin1', | |
104 \ 'ibm819' : 'latin1', | |
105 \ 'cp819' : 'latin1', | |
106 \ 'csisolatin1' : 'latin1', | |
107 \ 'iso_8859-2:1987' : 'iso-8859-2', | |
108 \ 'iso-ir-101' : 'iso-8859-2', | |
109 \ 'iso_8859-2' : 'iso-8859-2', | |
110 \ 'iso-8859-2' : 'iso-8859-2', | |
111 \ 'latin2' : 'iso-8859-2', | |
112 \ 'l2' : 'iso-8859-2', | |
113 \ 'csisolatin2' : 'iso-8859-2', | |
114 \ 'iso_8859-3:1988' : 'iso-8859-3', | |
115 \ 'iso-ir-109' : 'iso-8859-3', | |
116 \ 'iso_8859-3' : 'iso-8859-3', | |
117 \ 'iso-8859-3' : 'iso-8859-3', | |
118 \ 'latin3' : 'iso-8859-3', | |
119 \ 'l3' : 'iso-8859-3', | |
120 \ 'csisolatin3' : 'iso-8859-3', | |
121 \ 'iso_8859-4:1988' : 'iso-8859-4', | |
122 \ 'iso-ir-110' : 'iso-8859-4', | |
123 \ 'iso_8859-4' : 'iso-8859-4', | |
124 \ 'iso-8859-4' : 'iso-8859-4', | |
125 \ 'latin4' : 'iso-8859-4', | |
126 \ 'l4' : 'iso-8859-4', | |
127 \ 'csisolatin4' : 'iso-8859-4', | |
128 \ 'iso_8859-5:1988' : 'iso-8859-5', | |
129 \ 'iso-ir-144' : 'iso-8859-5', | |
130 \ 'iso_8859-5' : 'iso-8859-5', | |
131 \ 'iso-8859-5' : 'iso-8859-5', | |
132 \ 'cyrillic' : 'iso-8859-5', | |
133 \ 'csisolatincyrillic' : 'iso-8859-5', | |
134 \ 'iso_8859-6:1987' : 'iso-8859-6', | |
135 \ 'iso-ir-127' : 'iso-8859-6', | |
136 \ 'iso_8859-6' : 'iso-8859-6', | |
137 \ 'iso-8859-6' : 'iso-8859-6', | |
138 \ 'ecma-114' : 'iso-8859-6', | |
139 \ 'asmo-708' : 'iso-8859-6', | |
140 \ 'arabic' : 'iso-8859-6', | |
141 \ 'csisolatinarabic' : 'iso-8859-6', | |
142 \ 'iso_8859-7:1987' : 'iso-8859-7', | |
143 \ 'iso-ir-126' : 'iso-8859-7', | |
144 \ 'iso_8859-7' : 'iso-8859-7', | |
145 \ 'iso-8859-7' : 'iso-8859-7', | |
146 \ 'elot_928' : 'iso-8859-7', | |
147 \ 'ecma-118' : 'iso-8859-7', | |
148 \ 'greek' : 'iso-8859-7', | |
149 \ 'greek8' : 'iso-8859-7', | |
150 \ 'csisolatingreek' : 'iso-8859-7', | |
151 \ 'iso_8859-8:1988' : 'iso-8859-8', | |
152 \ 'iso-ir-138' : 'iso-8859-8', | |
153 \ 'iso_8859-8' : 'iso-8859-8', | |
154 \ 'iso-8859-8' : 'iso-8859-8', | |
155 \ 'hebrew' : 'iso-8859-8', | |
156 \ 'csisolatinhebrew' : 'iso-8859-8', | |
157 \ 'iso_8859-9:1989' : 'iso-8859-9', | |
158 \ 'iso-ir-148' : 'iso-8859-9', | |
159 \ 'iso_8859-9' : 'iso-8859-9', | |
160 \ 'iso-8859-9' : 'iso-8859-9', | |
161 \ 'latin5' : 'iso-8859-9', | |
162 \ 'l5' : 'iso-8859-9', | |
163 \ 'csisolatin5' : 'iso-8859-9', | |
164 \ 'iso-8859-10' : 'iso-8859-10', | |
165 \ 'iso-ir-157' : 'iso-8859-10', | |
166 \ 'l6' : 'iso-8859-10', | |
167 \ 'iso_8859-10:1992' : 'iso-8859-10', | |
168 \ 'csisolatin6' : 'iso-8859-10', | |
169 \ 'latin6' : 'iso-8859-10', | |
170 \ 'iso-8859-13' : 'iso-8859-13', | |
171 \ 'iso-8859-14' : 'iso-8859-14', | |
172 \ 'iso-ir-199' : 'iso-8859-14', | |
173 \ 'iso_8859-14:1998' : 'iso-8859-14', | |
174 \ 'iso_8859-14' : 'iso-8859-14', | |
175 \ 'latin8' : 'iso-8859-14', | |
176 \ 'iso-celtic' : 'iso-8859-14', | |
177 \ 'l8' : 'iso-8859-14', | |
178 \ 'iso-8859-15' : 'iso-8859-15', | |
179 \ 'iso_8859-15' : 'iso-8859-15', | |
180 \ 'latin-9' : 'iso-8859-15', | |
181 \ 'koi8-r' : 'koi8-r', | |
182 \ 'cskoi8r' : 'koi8-r', | |
183 \ 'koi8-u' : 'koi8-u', | |
184 \ 'macintosh' : 'macroman', | |
185 \ 'mac' : 'macroman', | |
186 \ 'csmacintosh' : 'macroman', | |
187 \ 'ibm437' : 'cp437', | |
188 \ 'cp437' : 'cp437', | |
189 \ '437' : 'cp437', | |
190 \ 'cspc8codepage437' : 'cp437', | |
191 \ 'ibm775' : 'cp775', | |
192 \ 'cp775' : 'cp775', | |
193 \ 'cspc775baltic' : 'cp775', | |
194 \ 'ibm850' : 'cp850', | |
195 \ 'cp850' : 'cp850', | |
196 \ '850' : 'cp850', | |
197 \ 'cspc850multilingual' : 'cp850', | |
198 \ 'ibm852' : 'cp852', | |
199 \ 'cp852' : 'cp852', | |
200 \ '852' : 'cp852', | |
201 \ 'cspcp852' : 'cp852', | |
202 \ 'ibm855' : 'cp855', | |
203 \ 'cp855' : 'cp855', | |
204 \ '855' : 'cp855', | |
205 \ 'csibm855' : 'cp855', | |
206 \ 'ibm857' : 'cp857', | |
207 \ 'cp857' : 'cp857', | |
208 \ '857' : 'cp857', | |
209 \ 'csibm857' : 'cp857', | |
210 \ 'ibm860' : 'cp860', | |
211 \ 'cp860' : 'cp860', | |
212 \ '860' : 'cp860', | |
213 \ 'csibm860' : 'cp860', | |
214 \ 'ibm861' : 'cp861', | |
215 \ 'cp861' : 'cp861', | |
216 \ '861' : 'cp861', | |
217 \ 'cp-is' : 'cp861', | |
218 \ 'csibm861' : 'cp861', | |
219 \ 'ibm862' : 'cp862', | |
220 \ 'cp862' : 'cp862', | |
221 \ '862' : 'cp862', | |
222 \ 'cspc862latinhebrew' : 'cp862', | |
223 \ 'ibm863' : 'cp863', | |
224 \ 'cp863' : 'cp863', | |
225 \ '863' : 'cp863', | |
226 \ 'csibm863' : 'cp863', | |
227 \ 'ibm865' : 'cp865', | |
228 \ 'cp865' : 'cp865', | |
229 \ '865' : 'cp865', | |
230 \ 'csibm865' : 'cp865', | |
231 \ 'ibm866' : 'cp866', | |
232 \ 'cp866' : 'cp866', | |
233 \ '866' : 'cp866', | |
234 \ 'csibm866' : 'cp866', | |
235 \ 'ibm869' : 'cp869', | |
236 \ 'cp869' : 'cp869', | |
237 \ '869' : 'cp869', | |
238 \ 'cp-gr' : 'cp869', | |
239 \ 'csibm869' : 'cp869', | |
240 \ 'windows-1250' : 'cp1250', | |
241 \ 'windows-1251' : 'cp1251', | |
242 \ 'windows-1253' : 'cp1253', | |
243 \ 'windows-1254' : 'cp1254', | |
244 \ 'windows-1255' : 'cp1255', | |
245 \ 'windows-1256' : 'cp1256', | |
246 \ 'windows-1257' : 'cp1257', | |
247 \ 'windows-1258' : 'cp1258', | |
248 \ 'extended_unix_code_packed_format_for_japanese' : 'euc-jp', | |
249 \ 'cseucpkdfmtjapanese' : 'euc-jp', | |
250 \ 'euc-jp' : 'euc-jp', | |
251 \ 'shift_jis' : 'sjis', | |
252 \ 'ms_kanji' : 'sjis', | |
253 \ 'sjis' : 'sjis', | |
254 \ 'csshiftjis' : 'sjis', | |
255 \ 'ibm-thai' : 'cp874', | |
256 \ 'csibmthai' : 'cp874', | |
257 \ 'ks_c_5601-1987' : 'cp949', | |
258 \ 'iso-ir-149' : 'cp949', | |
259 \ 'ks_c_5601-1989' : 'cp949', | |
260 \ 'ksc_5601' : 'cp949', | |
261 \ 'korean' : 'cp949', | |
262 \ 'csksc56011987' : 'cp949', | |
263 \ 'euc-kr' : 'euc-kr', | |
264 \ 'cseuckr' : 'euc-kr', | |
265 \ 'gbk' : 'cp936', | |
266 \ 'cp936' : 'cp936', | |
267 \ 'ms936' : 'cp936', | |
268 \ 'windows-936' : 'cp936', | |
269 \ 'gb_2312-80' : 'euc-cn', | |
270 \ 'iso-ir-58' : 'euc-cn', | |
271 \ 'chinese' : 'euc-cn', | |
272 \ 'csiso58gb231280' : 'euc-cn', | |
273 \ 'big5' : 'big5', | |
274 \ 'csbig5' : 'big5', | |
275 \ 'utf-8' : 'utf-8', | |
276 \ 'iso-10646-ucs-2' : 'ucs-2', | |
277 \ 'csunicode' : 'ucs-2', | |
278 \ 'utf-16' : 'utf-16', | |
279 \ 'utf-16be' : 'utf-16', | |
280 \ 'utf-16le' : 'utf-16le', | |
281 \ 'utf-32' : 'ucs-4', | |
282 \ 'utf-32be' : 'ucs-4', | |
283 \ 'utf-32le' : 'ucs-4le', | |
284 \ 'iso-10646-ucs-4' : 'ucs-4', | |
285 \ 'csucs4' : 'ucs-4' | |
286 \ } | |
287 lockvar g:tohtml#charset_to_encoding | |
288 "}}} | |
289 | |
290 func! tohtml#Convert2HTML(line1, line2) "{{{ | |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
291 let s:settings = tohtml#GetUserSettings() |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
292 |
2642 | 293 if !&diff || s:settings.diff_one_file "{{{ |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
294 if a:line2 >= a:line1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
295 let g:html_start_line = a:line1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
296 let g:html_end_line = a:line2 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
297 else |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
298 let g:html_start_line = a:line2 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
299 let g:html_end_line = a:line1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
300 endif |
2642 | 301 runtime syntax/2html.vim "}}} |
302 else "{{{ | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
303 let win_list = [] |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
304 let buf_list = [] |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
305 windo | if &diff | call add(win_list, winbufnr(0)) | endif |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
306 let s:settings.whole_filler = 1 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
307 let g:html_diff_win_num = 0 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
308 for window in win_list |
2642 | 309 " switch to the next buffer to convert |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
310 exe ":" . bufwinnr(window) . "wincmd w" |
2642 | 311 |
312 " figure out whether current charset and encoding will work, if not | |
313 " default to UTF-8 | |
314 if !exists('g:html_use_encoding') && | |
2788 | 315 \ (((&l:fileencoding=='' || (&l:buftype!='' && &l:buftype!=?'help')) |
316 \ && &encoding!=?s:settings.vim_encoding) | |
317 \ || &l:fileencoding!='' && &l:fileencoding!=?s:settings.vim_encoding) | |
2642 | 318 echohl WarningMsg |
319 echomsg "TOhtml: mismatched file encodings in Diff buffers, using UTF-8" | |
320 echohl None | |
321 let s:settings.vim_encoding = 'utf-8' | |
322 let s:settings.encoding = 'UTF-8' | |
323 endif | |
324 | |
325 " set up for diff-mode conversion | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
326 let g:html_start_line = 1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
327 let g:html_end_line = line('$') |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
328 let g:html_diff_win_num += 1 |
2642 | 329 |
330 " convert this file | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
331 runtime syntax/2html.vim |
2642 | 332 |
333 " remember the HTML buffer for later combination | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
334 call add(buf_list, bufnr('%')) |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
335 endfor |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
336 unlet g:html_diff_win_num |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
337 call tohtml#Diff2HTML(win_list, buf_list) |
2642 | 338 endif "}}} |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
339 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
340 unlet g:html_start_line |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
341 unlet g:html_end_line |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
342 unlet s:settings |
2642 | 343 endfunc "}}} |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
344 |
2642 | 345 func! tohtml#Diff2HTML(win_list, buf_list) "{{{ |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
346 let xml_line = "" |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
347 let tag_close = '>' |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
348 |
2546
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
349 let s:old_paste = &paste |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
350 set paste |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
351 let s:old_magic = &magic |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
352 set magic |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
353 |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
354 if s:settings.use_xhtml |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
355 if s:settings.encoding != "" |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
356 let xml_line = "<?xml version=\"1.0\" encoding=\"" . s:settings.encoding . "\"?>" |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
357 else |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
358 let xml_line = "<?xml version=\"1.0\"?>" |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
359 endif |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
360 let tag_close = ' />' |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
361 endif |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
362 |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
363 let style = [s:settings.use_xhtml ? "" : '-->'] |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
364 let body_line = '' |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
365 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
366 let html = [] |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
367 if s:settings.use_xhtml |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
368 call add(html, xml_line) |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
369 endif |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
370 if s:settings.use_xhtml |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
371 call add(html, "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">") |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
372 call add(html, '<html xmlns="http://www.w3.org/1999/xhtml">') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
373 elseif s:settings.use_css && !s:settings.no_pre |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
374 call add(html, "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">") |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
375 call add(html, '<html>') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
376 else |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
377 call add(html, '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
378 call add(html, ' "http://www.w3.org/TR/html4/loose.dtd">') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
379 call add(html, '<html>') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
380 endif |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
381 call add(html, '<head>') |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
382 |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
383 " include encoding as close to the top as possible, but only if not already |
2642 | 384 " contained in XML information |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
385 if s:settings.encoding != "" && !s:settings.use_xhtml |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
386 call add(html, "<meta http-equiv=\"content-type\" content=\"text/html; charset=" . s:settings.encoding . '"' . tag_close) |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
387 endif |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
388 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
389 call add(html, '<title>diff</title>') |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
390 call add(html, '<meta name="Generator" content="Vim/'.v:version/100.'.'.v:version%100.'"'.tag_close) |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
391 call add(html, '<meta name="plugin-version" content="'.g:loaded_2html_plugin.'"'.tag_close) |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
392 call add(html, '<meta name="settings" content="'. |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
393 \ join(filter(keys(s:settings),'s:settings[v:val]'),','). |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
394 \ '"'.tag_close) |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
395 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
396 call add(html, '</head>') |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
397 let body_line_num = len(html) |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
398 call add(html, '<body>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
399 call add(html, '<table border="1" width="100%">') |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
400 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
401 call add(html, '<tr>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
402 for buf in a:win_list |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
403 call add(html, '<th>'.bufname(buf).'</th>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
404 endfor |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
405 call add(html, '</tr><tr>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
406 |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
407 let diff_style_start = 0 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
408 let insert_index = 0 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
409 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
410 for buf in a:buf_list |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
411 let temp = [] |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
412 exe bufwinnr(buf) . 'wincmd w' |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
413 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
414 " If text is folded because of user foldmethod settings, etc. we don't want |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
415 " to act on everything in a fold by mistake. |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
416 setlocal nofoldenable |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
417 |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
418 " When not using CSS or when using xhtml, the <body> line can be important. |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
419 " Assume it will be the same for all buffers and grab it from the first |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
420 " buffer. Similarly, need to grab the body end line as well. |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
421 if body_line == '' |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
422 1 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
423 call search('<body') |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
424 let body_line = getline('.') |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
425 $ |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
426 call search('</body>', 'b') |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
427 let s:body_end_line = getline('.') |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
428 endif |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
429 |
2642 | 430 " Grab the style information. Some of this will be duplicated so only insert |
431 " it if it's not already there. {{{ | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
432 1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
433 let style_start = search('^<style type="text/css">') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
434 1 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
435 let style_end = search('^</style>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
436 if style_start > 0 && style_end > 0 |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
437 let buf_styles = getline(style_start + 1, style_end - 1) |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
438 for a_style in buf_styles |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
439 if index(style, a_style) == -1 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
440 if diff_style_start == 0 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
441 if a_style =~ '\<Diff\(Change\|Text\|Add\|Delete\)' |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
442 let diff_style_start = len(style)-1 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
443 endif |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
444 endif |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
445 call insert(style, a_style, insert_index) |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
446 let insert_index += 1 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
447 endif |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
448 endfor |
2642 | 449 endif " }}} |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
450 |
2642 | 451 " everything new will get added before the diff styles so diff highlight |
452 " properly overrides normal highlight | |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
453 if diff_style_start != 0 |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
454 let insert_index = diff_style_start |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
455 endif |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
456 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
457 " Delete those parts that are not needed so |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
458 " we can include the rest into the resulting table |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
459 1,/^<body/d_ |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
460 $ |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
461 ?</body>?,$d_ |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
462 let temp = getline(1,'$') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
463 " undo deletion of start and end part |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
464 " so we can later save the file as valid html |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
465 " TODO: restore using grabbed lines if undolevel is 1? |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
466 normal 2u |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
467 if s:settings.use_css |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
468 call add(html, '<td valign="top"><div>') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
469 elseif s:settings.use_xhtml |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
470 call add(html, '<td nowrap="nowrap" valign="top"><div>') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
471 else |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
472 call add(html, '<td nowrap valign="top"><div>') |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
473 endif |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
474 let html += temp |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
475 call add(html, '</div></td>') |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
476 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
477 " Close this buffer |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
478 " TODO: the comment above says we're going to allow saving the file |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
479 " later...but here we discard it? |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
480 quit! |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
481 endfor |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
482 |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
483 let html[body_line_num] = body_line |
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
484 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
485 call add(html, '</tr>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
486 call add(html, '</table>') |
2432
80229a724a11
Updated runtime files. :TOhtml improvements by Benjamin Fritz.
Bram Moolenaar <bram@vim.org>
parents:
2401
diff
changeset
|
487 call add(html, s:body_end_line) |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
488 call add(html, '</html>') |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
489 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
490 let i = 1 |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
491 let name = "Diff" . (s:settings.use_xhtml ? ".xhtml" : ".html") |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
492 " Find an unused file name if current file name is already in use |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
493 while filereadable(name) |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
494 let name = substitute(name, '\d*\.x\?html$', '', '') . i . '.' . fnamemodify(copy(name), ":t:e") |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
495 let i += 1 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
496 endwhile |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
497 exe "topleft new " . name |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
498 setlocal modifiable |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
499 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
500 " just in case some user autocmd creates content in the new buffer, make sure |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
501 " it is empty before proceeding |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
502 %d |
2642 | 503 |
504 " set the fileencoding to match the charset we'll be using | |
505 let &l:fileencoding=s:settings.vim_encoding | |
506 | |
507 " According to http://www.w3.org/TR/html4/charset.html#doc-char-set, the byte | |
508 " order mark is highly recommend on the web when using multibyte encodings. But, | |
509 " it is not a good idea to include it on UTF-8 files. Otherwise, let Vim | |
510 " determine when it is actually inserted. | |
511 if s:settings.vim_encoding == 'utf-8' | |
512 setlocal nobomb | |
513 else | |
514 setlocal bomb | |
515 endif | |
516 | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
517 call append(0, html) |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
518 |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
519 if len(style) > 0 |
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
520 1 |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
521 let style_start = search('^</head>')-1 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
522 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
523 " Insert javascript to toggle matching folds open and closed in all windows, |
2642 | 524 " if dynamic folding is active. {{{ |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
525 if s:settings.dynamic_folds |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
526 call append(style_start, [ |
2334
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
527 \ "<script type='text/javascript'>", |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
528 \ s:settings.use_xhtml ? '//<![CDATA[' : " <!--", |
2334
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
529 \ " function toggleFold(objID)", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
530 \ " {", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
531 \ " for (win_num = 1; win_num <= ".len(a:buf_list)."; win_num++)", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
532 \ " {", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
533 \ " var fold;", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
534 \ ' fold = document.getElementById("win"+win_num+objID);', |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
535 \ " if(fold.className == 'closed-fold')", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
536 \ " {", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
537 \ " fold.className = 'open-fold';", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
538 \ " }", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
539 \ " else if (fold.className == 'open-fold')", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
540 \ " {", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
541 \ " fold.className = 'closed-fold';", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
542 \ " }", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
543 \ " }", |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
544 \ " }", |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
545 \ s:settings.use_xhtml ? '//]]>' : " -->", |
2334
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
546 \ "</script>" |
3c9324c0800e
Improved :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2321
diff
changeset
|
547 \ ]) |
2642 | 548 endif "}}} |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
549 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
550 " Insert styles from all the generated html documents and additional styles |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
551 " for the table-based layout of the side-by-side diff. The diff should take |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
552 " up the full browser window (but not more), and be static in size, |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
553 " horizontally scrollable when the lines are too long. Otherwise, the diff |
2642 | 554 " is pretty useless for really long lines. {{{ |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
555 if s:settings.use_css |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
556 call append(style_start, |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
557 \ ['<style type="text/css">']+ |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
558 \ style+ |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
559 \ [ s:settings.use_xhtml ? '' : '<!--', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
560 \ 'table { table-layout: fixed; }', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
561 \ 'html, body, table, tbody { width: 100%; margin: 0; padding: 0; }', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
562 \ 'th, td { width: '.printf("%.1f",100.0/len(a:win_list)).'%; }', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
563 \ 'td div { overflow: auto; }', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
564 \ s:settings.use_xhtml ? '' : '-->', |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
565 \ '</style>' |
2642 | 566 \]) |
567 endif "}}} | |
2304
a59e6ac5ed28
When the buffer is in diff mode, have :TOhtml create HTML to show the diff
Bram Moolenaar <bram@vim.org>
parents:
diff
changeset
|
568 endif |
2546
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
569 |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
570 let &paste = s:old_paste |
0d3f0e3d289b
Updates for :TOhtml. (Benjamin Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2508
diff
changeset
|
571 let &magic = s:old_magic |
2642 | 572 endfunc "}}} |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
573 |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
574 " Gets a single user option and sets it in the passed-in Dict, or gives it the |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
575 " default value if the option doesn't actually exist. |
2642 | 576 func! tohtml#GetOption(settings, option, default) "{{{ |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
577 if exists('g:html_'.a:option) |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
578 let a:settings[a:option] = g:html_{a:option} |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
579 else |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
580 let a:settings[a:option] = a:default |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
581 endif |
2642 | 582 endfunc "}}} |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
583 |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
584 " returns a Dict containing the values of all user options for 2html, including |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
585 " default values for those not given an explicit value by the user. Discards the |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
586 " html_ prefix of the option for nicer looking code. |
2642 | 587 func! tohtml#GetUserSettings() "{{{ |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
588 if exists('s:settings') |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
589 " just restore the known options if we've already retrieved them |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
590 return s:settings |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
591 else |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
592 " otherwise figure out which options are set |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
593 let user_settings = {} |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
594 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
595 " Define the correct option if the old option name exists and we haven't |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
596 " already defined the correct one. Maybe I'll put out a warnig message about |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
597 " this sometime and remove the old option entirely at some even later time, |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
598 " but for now just silently accept the old option. |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
599 if exists('g:use_xhtml') && !exists("g:html_use_xhtml") |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
600 let g:html_use_xhtml = g:use_xhtml |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
601 endif |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
602 |
2642 | 603 " get current option settings with appropriate defaults {{{ |
2681 | 604 call tohtml#GetOption(user_settings, 'no_progress', !has("statusline") ) |
605 call tohtml#GetOption(user_settings, 'diff_one_file', 0 ) | |
606 call tohtml#GetOption(user_settings, 'number_lines', &number ) | |
2788 | 607 call tohtml#GetOption(user_settings, 'pre_wrap', &wrap ) |
2681 | 608 call tohtml#GetOption(user_settings, 'use_css', 1 ) |
609 call tohtml#GetOption(user_settings, 'ignore_conceal', 0 ) | |
610 call tohtml#GetOption(user_settings, 'ignore_folding', 0 ) | |
611 call tohtml#GetOption(user_settings, 'dynamic_folds', 0 ) | |
612 call tohtml#GetOption(user_settings, 'no_foldcolumn', 0 ) | |
613 call tohtml#GetOption(user_settings, 'hover_unfold', 0 ) | |
614 call tohtml#GetOption(user_settings, 'no_pre', 0 ) | |
615 call tohtml#GetOption(user_settings, 'whole_filler', 0 ) | |
616 call tohtml#GetOption(user_settings, 'use_xhtml', 0 ) | |
2642 | 617 " }}} |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
618 |
2642 | 619 " override those settings that need it {{{ |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
620 |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
621 " hover opening implies dynamic folding |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
622 if user_settings.hover_unfold |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
623 let user_settings.dynamic_folds = 1 |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
624 endif |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
625 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
626 " ignore folding overrides dynamic folding |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
627 if user_settings.ignore_folding && user_settings.dynamic_folds |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
628 let user_settings.dynamic_folds = 0 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
629 let user_settings.hover_unfold = 0 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
630 endif |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
631 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
632 " dynamic folding with no foldcolumn implies hover opens |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
633 if user_settings.dynamic_folds && user_settings.no_foldcolumn |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
634 let user_settings.hover_unfold = 1 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
635 endif |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
636 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
637 " dynamic folding implies css |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
638 if user_settings.dynamic_folds |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
639 let user_settings.use_css = 1 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
640 endif |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
641 |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
642 " if we're not using CSS we cannot use a pre section because <font> tags |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
643 " aren't allowed inside a <pre> block |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
644 if !user_settings.use_css |
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
645 let user_settings.no_pre = 1 |
2788 | 646 endif |
647 | |
648 " pre_wrap doesn't do anything if not using pre or not using CSS | |
649 if user_settings.no_pre || !user_settings.use_css | |
650 let user_settings.pre_wrap=0 | |
651 endif | |
652 "}}} | |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
653 |
2681 | 654 " set up expand_tabs option after all the overrides so we know the |
655 " appropriate defaults {{{ | |
656 if user_settings.no_pre == 0 | |
657 call tohtml#GetOption(user_settings, | |
658 \ 'expand_tabs', | |
659 \ &expandtab || &ts != 8 || user_settings.number_lines || | |
660 \ (user_settings.dynamic_folds && !user_settings.no_foldcolumn)) | |
661 else | |
662 let user_settings.expand_tabs = 1 | |
663 endif | |
664 " }}} | |
665 | |
2642 | 666 if exists("g:html_use_encoding") "{{{ |
667 " user specified the desired MIME charset, figure out proper | |
668 " 'fileencoding' from it or warn the user if we cannot | |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
669 let user_settings.encoding = g:html_use_encoding |
2642 | 670 let user_settings.vim_encoding = tohtml#EncodingFromCharset(g:html_use_encoding) |
671 if user_settings.vim_encoding == '' | |
672 echohl WarningMsg | |
673 echomsg "TOhtml: file encoding for" | |
674 \ g:html_use_encoding | |
675 \ "unknown, please set 'fileencoding'" | |
676 echohl None | |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
677 endif |
2642 | 678 else |
679 " Figure out proper MIME charset from 'fileencoding' if possible | |
2788 | 680 if &l:fileencoding != '' |
681 " If the buffer is not a "normal" type, the 'fileencoding' value may not | |
682 " be trusted; since the buffer should not be written the fileencoding is | |
683 " not intended to be used. | |
684 if &l:buftype=='' || &l:buftype==?'help' | |
685 let user_settings.vim_encoding = &l:fileencoding | |
686 call tohtml#CharsetFromEncoding(user_settings) | |
687 else | |
688 let user_settings.encoding = '' " trigger detection using &encoding | |
689 endif | |
2642 | 690 endif |
691 | |
692 " else from 'encoding' if possible | |
693 if &l:fileencoding == '' || user_settings.encoding == '' | |
694 let user_settings.vim_encoding = &encoding | |
695 call tohtml#CharsetFromEncoding(user_settings) | |
696 endif | |
697 | |
698 " else default to UTF-8 and warn user | |
699 if user_settings.encoding == '' | |
700 let user_settings.vim_encoding = 'utf-8' | |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
701 let user_settings.encoding = 'UTF-8' |
2642 | 702 echohl WarningMsg |
703 echomsg "TOhtml: couldn't determine MIME charset, using UTF-8" | |
704 echohl None | |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
705 endif |
2642 | 706 endif "}}} |
2508
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
707 |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
708 " TODO: font |
7e008c174cc3
Updates for :TOhtml. (Ben Fritz)
Bram Moolenaar <bram@vim.org>
parents:
2496
diff
changeset
|
709 |
2496
a29075150aee
Improve handling of user settings in :TOhtml. Default to generating CSS.
Bram Moolenaar <bram@vim.org>
parents:
2432
diff
changeset
|
710 return user_settings |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
711 endif |
2642 | 712 endfunc "}}} |
713 | |
714 " get the proper HTML charset name from a Vim encoding option. | |
715 function! tohtml#CharsetFromEncoding(settings) "{{{ | |
716 let l:vim_encoding = a:settings.vim_encoding | |
717 if exists('g:html_charset_override') && has_key(g:html_charset_override, l:vim_encoding) | |
718 let a:settings.encoding = g:html_charset_override[l:vim_encoding] | |
719 else | |
720 if l:vim_encoding =~ '^8bit\|^2byte' | |
721 " 8bit- and 2byte- prefixes are to indicate encodings available on the | |
722 " system that Vim will convert with iconv(), look up just the encoding name, | |
723 " not Vim's prefix. | |
724 let l:vim_encoding = substitute(l:vim_encoding, '^8bit-\|^2byte-', '', '') | |
725 endif | |
726 if has_key(g:tohtml#encoding_to_charset, l:vim_encoding) | |
727 let a:settings.encoding = g:tohtml#encoding_to_charset[l:vim_encoding] | |
728 else | |
729 let a:settings.encoding = "" | |
730 endif | |
731 endif | |
732 if a:settings.encoding != "" | |
733 let l:vim_encoding = tohtml#EncodingFromCharset(a:settings.encoding) | |
734 if l:vim_encoding != "" | |
735 " if the Vim encoding to HTML encoding conversion is set up (by default or | |
736 " by the user) to convert to a different encoding, we need to also change | |
737 " the Vim encoding of the new buffer | |
738 let a:settings.vim_encoding = l:vim_encoding | |
739 endif | |
740 endif | |
741 endfun "}}} | |
742 | |
743 " Get the proper Vim encoding option setting from an HTML charset name. | |
744 function! tohtml#EncodingFromCharset(encoding) "{{{ | |
745 if exists('g:html_encoding_override') && has_key(g:html_encoding_override, a:encoding) | |
746 return g:html_encoding_override[a:encoding] | |
747 elseif has_key(g:tohtml#charset_to_encoding, tolower(a:encoding)) | |
748 return g:tohtml#charset_to_encoding[tolower(a:encoding)] | |
749 else | |
750 return "" | |
751 endif | |
752 endfun "}}} | |
2321
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
753 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
754 let &cpo = s:cpo_sav |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
755 unlet s:cpo_sav |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
756 |
1902913f2049
Improved version of 2html.vim.
Bram Moolenaar <bram@vim.org>
parents:
2304
diff
changeset
|
757 " Make sure any patches will probably use consistent indent |
2642 | 758 " vim: ts=8 sw=2 sts=2 noet fdm=marker |