Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Syntax highlighting with vim & Ruby

From: http://www.ruby-forum.com/topic/64262

This snippet will convert source code files to syntax-colored html files.
usage: vim-syntax-highlighting.rb src.rb src.html


   1  
   2  
   3  require 'tempfile'
   4  
   5  $VERBOSE=nil
   6  STDERR.reopen(Tempfile::new($$)) unless STDIN.tty?
   7  
   8  fin, fout, _ = ARGV
   9  fin = ((fin.nil? or fin == '-') ? STDIN : open(fin))
  10  fout = ((fout.nil? or fout == '-') ? STDOUT : open(fout,'w+'))
  11  
  12  ts = Tempfile::new($$), Tempfile::new($$)
  13  ts[0].write fin.read
  14  ts.each{|t| t.close}
  15  command = %Q( vim -f +'syn on' +'set filetype=ruby' +'set background=light' +'run! syntax/2html.vim' +'w! #{ ts[1].path }' +'qa!' - < #{ ts[0].path } > /dev/null 2>&1 )
  16  #command = %Q( vim -f +'syn on' +'set filetype=c' +'set background=dark' +'run! syntax/2html.vim' +'w! #{ ts[1].path }' +'qa!' - < #{ ts[0].path } > /dev/null 2>&1 )
  17  system command
  18  ts.each{|t| t.open; t.rewind}
  19  fout.write(ts[1].read)
  20  ts.each{|t| t.close!}
  21  
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS