Ruby Syntax highlighting library

I’m wanting to use the Syntax library, but I don’t know how to make use
of it. Let’s say I had the following:

  # comments go here
  def ruby_method
    words = Word.find_all
  end

I’d like this to be formatted where I can apply styles to the comments,
and the def and so on.

Can someone help me out with this? Not to be rude, but I’ve checked out
the syntax site, and I’m not sure I know what to do from there, so could
someone post a code snippet example of how to use it? Thanks in
advance.

On Sat, Dec 09, 2006 at 06:09:23AM +0100, ryan wrote:

I’d like this to be formatted where I can apply styles to the comments,
and the def and so on.

Can someone help me out with this? Not to be rude, but I’ve checked out
the syntax site, and I’m not sure I know what to do from there, so could
someone post a code snippet example of how to use it? Thanks in
advance.

This is taken from the manual and modified a bit (convertor needed an s
in the end):

require ‘rubygems’

Step 1: require the HTML convertor

require ‘syntax/convertors/html’

Step 2: get an instance of the HTML convertor for the Ruby syntax

convertor = Syntax::Convertors::HTML.for_syntax “ruby”

Step 3: convert the text to HTML

puts convertor.convert( File.read( “hilight.rb” ) )

It will output the contents of hilight.rb as syntax highlighted HTML to
the console. Is this enough?


Cheers,

  • Jacob A.