The Accidental Rubyist

invalid byte sequence in UTF-8

Quick command-line syntax highlighting (coderay)

leave a comment »

 1 #!/usr/bin/env ruby
 2 # courtesy: Helder
 3 # http://obvio171.wordpress.com/2007/06/03/colorful-ruby-code-for-your-blog/
 4 # modified to output to stdout so can be used as a filter
 5 #  2008-09-03 23:22 
 6 require 'rubygems'
 7 require 'coderay'
 8
 9 if ARGV.length != 1
10   puts "Wrong number of arguments. Use: codecolor.rb <source_file>"
11   exit
12 end
13
14 rb_file = File.expand_path(ARGV[0])
15
16 print CodeRay.encode(
17          File.read(rb_file),
18          :ruby,
19          :html,
20          :line_numbers => :inline,
21          :hint => :info,
22          :css => :style,
23          :wrap => :div
24        )
25 

Courtesy: Coderay examples

#!/usr/bin/env ruby
require 'rubygems'
require 'coderay'
print CodeRay.scan(File.read(ARGV[0]), :ruby).div
#print "---------------------\n\n"
#print CodeRay.scan_file('codecolor.rb').html.div


# align all text flush right on a 79-column width
$ cat | ruby -ne ‘printf(“%79s”, $_)’

Advertisements

Written by totalrecall

September 3, 2008 at 11:50 pm

Posted in ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: