comparison runtime/syntax/2html.vim @ 29:ac33b7c03fac v7.0018

updated for version 7.0018
author vimboss
date Mon, 11 Oct 2004 10:16:09 +0000
parents 3fc0f57ecb91
children 41f9fd58cf13
comparison
equal deleted inserted replaced
28:726bdc53fa49 29:ac33b7c03fac
1 " Vim syntax support file 1 " Vim syntax support file
2 " Maintainer: Bram Moolenaar <Bram@vim.org> 2 " Maintainer: Bram Moolenaar <Bram@vim.org>
3 " Last Change: 2004 May 31 3 " Last Change: 2004 Oct 10
4 " (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>) 4 " (modified by David Ne\v{c}as (Yeti) <yeti@physics.muni.cz>)
5 " (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>) 5 " (XHTML support by Panagiotis Issaris <takis@lumumba.luc.ac.be>)
6 6
7 " Transform a file into HTML, using the current syntax highlighting. 7 " Transform a file into HTML, using the current syntax highlighting.
8 8
236 endif 236 endif
237 else 237 else
238 let s:end = line("$") 238 let s:end = line("$")
239 endif 239 endif
240 240
241 " Closed folds are kept in the HTML. Prepare the closed fold template text.
242 if has('folding')
243 let s:c = &fillchars[matchend(&fillchars, 'fold:')]
244 if s:c == ''
245 let s:c = '-'
246 endif
247 let s:htmlfoldtext = '+' . s:c
248 while strlen(s:htmlfoldtext) < &columns
249 let s:htmlfoldtext = s:htmlfoldtext . s:c
250 endwhile
251 unlet s:c
252 endif
253
254
241 while s:lnum <= s:end 255 while s:lnum <= s:end
242 256
243 " Get the current line 257 " Get the current line
244 let s:line = getline(s:lnum) 258 let s:line = getline(s:lnum)
245 let s:len = strlen(s:line)
246 let s:new = "" 259 let s:new = ""
247 260
248 if s:numblines 261 if has('folding') && foldclosed(s:lnum) > -1
249 let s:new = '<span class="lnr">' . strpart(' ', 0, strlen(line("$")) - strlen(s:lnum)) . s:lnum . '</span> ' 262 "
250 endif 263 " This is the beginning of a folded block
251 264 "
252 " Loop over each character in the line 265 if s:numblines
253 let s:col = 1 266 let s:new = strpart(' ', 0, strlen(line("$")) - strlen(s:lnum)) . s:lnum . ' '
254 while s:col <= s:len 267 endif
255 let s:startcol = s:col " The start column for processing text 268 let s:line = foldtextresult(s:lnum)
256 let s:id = synID(s:lnum, s:col, 1) 269
257 let s:col = s:col + 1 270 let s:new = s:new . s:line
258 " Speed loop (it's small - that's the trick) 271 if !exists("html_no_pre")
259 " Go along till we find a change in synID 272 let s:new = s:new . strpart(s:htmlfoldtext, strlen(s:new))
260 while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile 273 endif
261 274
262 " Output the text with the same synID, with class set to {s:id_name} 275 " Replace the reserved html characters
263 let s:id = synIDtrans(s:id) 276 let s:new = substitute(substitute(substitute(substitute(substitute(s:new, '&', '\&amp;', 'g'), '<', '\&lt;', 'g'), '>', '\&gt;', 'g'), '"', '\&quot;', 'g'), "\x0c", '<hr class="PAGE-BREAK">', 'g')
264 let s:id_name = synIDattr(s:id, "name", s:whatterm) 277
265 let s:new = s:new . '<span class="' . s:id_name . '">' . substitute(substitute(substitute(substitute(substitute(strpart(s:line, s:startcol - 1, s:col - s:startcol), '&', '\&amp;', 'g'), '<', '\&lt;', 'g'), '>', '\&gt;', 'g'), '"', '\&quot;', 'g'), "\x0c", '<hr class="PAGE-BREAK">', 'g') . '</span>' 278 let s:id_name = "Folded"
279 let s:id = hlID(s:id_name)
280 let s:new = '<span class="' . s:id_name . '">' . s:new . '</span>'
266 " Add the class to class list if it's not there yet 281 " Add the class to class list if it's not there yet
267 if stridx(s:idlist, "," . s:id . ",") == -1 282 if stridx(s:idlist, "," . s:id . ",") == -1
268 let s:idlist = s:idlist . s:id . "," 283 let s:idlist = s:idlist . s:id . ","
269 endif 284 endif
270 285
271 if s:col > s:len 286 " Skip to the end of the fold
272 break 287 let s:lnum = foldclosedend(s:lnum)
273 endif 288
274 endwhile 289 else
290 "
291 " A line that is not folded.
292 "
293 let s:len = strlen(s:line)
294
295 if s:numblines
296 let s:new = '<span class="lnr">' . strpart(' ', 0, strlen(line("$")) - strlen(s:lnum)) . s:lnum . '</span> '
297 endif
298
299 " Loop over each character in the line
300 let s:col = 1
301 while s:col <= s:len
302 let s:startcol = s:col " The start column for processing text
303 let s:id = synID(s:lnum, s:col, 1)
304 let s:col = s:col + 1
305 " Speed loop (it's small - that's the trick)
306 " Go along till we find a change in synID
307 while s:col <= s:len && s:id == synID(s:lnum, s:col, 1) | let s:col = s:col + 1 | endwhile
308
309 " Output the text with the same synID, with class set to {s:id_name}
310 let s:id = synIDtrans(s:id)
311 let s:id_name = synIDattr(s:id, "name", s:whatterm)
312 let s:new = s:new . '<span class="' . s:id_name . '">' . substitute(substitute(substitute(substitute(substitute(strpart(s:line, s:startcol - 1, s:col - s:startcol), '&', '\&amp;', 'g'), '<', '\&lt;', 'g'), '>', '\&gt;', 'g'), '"', '\&quot;', 'g'), "\x0c", '<hr class="PAGE-BREAK">', 'g') . '</span>'
313 " Add the class to class list if it's not there yet
314 if stridx(s:idlist, "," . s:id . ",") == -1
315 let s:idlist = s:idlist . s:id . ","
316 endif
317
318 if s:col > s:len
319 break
320 endif
321 endwhile
322 endif
275 323
276 " Expand tabs 324 " Expand tabs
277 let s:pad=0 325 let s:pad=0
278 let s:start = 0 326 let s:start = 0
279 let s:idx = stridx(s:line, "\t") 327 let s:idx = stridx(s:line, "\t")