Found out about this nice gem that does syntax highlighting of Ruby code (and C, Delphi, HML, RHML and Nitro-HTML for now) and outputs it as a stand-alone HTML. Perfect for blogging. I had found some other one some time ago that needed javascript, and it’s not every blogging service that lets you add that kinda stuff to your posts.
There are many configurable options, other types of output and stuff, you can find all that (very well documented) at CodeRay’s website.
So as a try-out, here’s the output of a little script to color ruby code, run on itself:
1 #!/usr/bin/env ruby 2 require 'rubygems' 3 require 'coderay' 4 5 if ARGV.length != 1 6 puts "Wrong number of arguments. Use: color_html <source_file>" 7 exit 8 end 9 10 rb_file = File.expand_path(ARGV[0]) 11 if rb_file.split('.')[-1] != 'rb' 12 puts "Not a .rb file" 13 exit 14 end 15 16 html_file = rb_file.split('.')[0..-2].join('.') << '.html' 17 if File.exists? html_file 18 puts "File #{html_file} exists. nOverwrite it? (y/N)" 19 # need to make STDIN explicit because there's a filename in the 20 # command-line argument (gets defaults to reading from it) 21 if STDIN.gets.strip == 'y' 22 File.delete(html_file) 23 else 24 exit(true) 25 end 26 end 27 28 File.open(html_file,'w') do |f| 29 f << CodeRay.encode( 30 File.read(rb_file), 31 :ruby, 32 :html, 33 :line_numbers => :inline, 34 :hint => :info, 35 :css => :style, 36 :wrap => :div 37 ) 38 end 39 40 puts "Done! Thanks for coming! =)"
coComment one click too annoying
February 25, 2006 — obvio171Stowe Boyd has it right about coComment:
“They should roll out a plug-in for the major blog services so that CoCommenting is natively supported. I, as a blogger, would install the plugin, and then CoComment could look the user up based on the email address they leave behind in the comment fields.”
Out of the 10 last times I left a comment somewhere, in about 12 I forgot to push the friggin’ button.
Thankfully, they said they’re working on it.