Saturday, November 29, 2008

Syntax Highlighting In Blogger


I have pulled various tricks in the past to get syntax highlighting in my code samples. In the past I only had highlighting for ruby code. I think I finally have a good solution and it works for any C style language.

Luka Marinko's blog has simple instructions to get this to work. Thanks Luka! Now here is some nonsense code to show what kind of highlighting you get with Java, Python, and Ruby. All the useless imports and requires are just so we can see those kinds of statements getting highlighted.
JAVA

import java.io.*;

class HelloWorld{
public static void main(String[] args) {
hello();
}

public static void hello(){
System.out.println("hello world");
}

}

RUBY

require 'rubygems'
class HelloWorld
def initialize
puts "hello world"
end
end

HelloWorld.new

PYTHON

import sys
class HelloWorld:
def __init__(self):
print "hello world"

HelloWorld()

1 comment:

Unknown said...

There is also a plugin for wordpress which I have been using, I guess its using the same stuff underneath, but the syntax for creating your code snippet is slightly different. Instructions for installation are at:

http://wordpress.org/extend/plugins/google-syntax-highlighter/installation/