Saturday, January 31, 2009

Syntax Color Highlight Test

This is a test of syntax highlighting

require 'rubygems'
require 'ramaze'

# you can access it now with http://localhost:7000/
# This should output
# Hello, World!
# in your browser

class MainController < Ramaze::Controller
def index
"Hello, World!"
end
end

Ramaze.start
OK, as long as I've figured this out, I might as well document how I did it in case someone else needs it. On ^ manveru's advice, I took a look at MaRuKu. MaRuKu is a Markdown language. To use it, just
gem install maruku
To syntax highlight ruby source copy the ruby source to a new file, move the code in four (4) spaces or one tab, and add the following line at the end
http://maruku.rubyforge.org/maruku.html
in the example above I copied our hello.rb to hello.rb.md, indented the entire file, and finally added the line. Next run ramaku on the new file
ramaku hello.rb.md
and this should produce a new file hello.rb.html
From this just grab the items in the within the <pre> tags and then paste it into your blog (or wherever). The only other thing to do is put the CSS into your blog's HTML. I added the following
.ruby .normal {}
.ruby .comment { color: #005; font-style: italic; }
.ruby .keyword { color: #A00; font-weight: bold; }
.ruby .method { color: #077; }
.ruby .class { color: #074; }
.ruby .module { color: #050; }
.ruby .punct { color: #447; font-weight: bold; }
.ruby .symbol { color: #099; }
.ruby .string { color: #944; background: #FFE; }
.ruby .char { color: #F07; }
.ruby .ident { color: #004; }
.ruby .constant { color: #07F; }
.ruby .regex { color: #B66; background: #FEF; }
.ruby .number { color: #F99; }
.ruby .attribute { color: #7BB; }
.ruby .global { color: #7FB; }
.ruby .expr { color: #227; }
.ruby .escape { color: #277; }


as part of a style tag right before the closing of the head tag.

Let me know if this makes sense to everyone and if not, I'll try to explain it a bit better. To be honest, I wasn't all that interested in doing a lot of work for this so there's a bit of trial and error rather than true understanding of what's really going on here.

No comments:

Post a Comment