Home > blog, tech, wordpress > Formatting source in blogs hosted on WordPress

Formatting source in blogs hosted on WordPress

I sometimes post snippets of code on this blog. I have been searching for a way to provide proper syntax highlighting for the code I post here. There are many wordpress plugins which provide proper syntax highlighting, but since I use the hosted WordPress service, I cannot use any of those. GNU Sourcehighlight is the standard program people use of generating source highlighting, but for some strange reason I could not get that to compile on my iBook.

While looking for alternatives on the web, I noticed a package called Highlight. Highlight can generate syntax highlighted HTML files from program source files. It supports over 120 programming languages! I tried it few months ago, but soon ran into a limitation. Highlight output uses CSS classes and style definitions; to make it convenient to post code here, I needed a package that generated inline CSS styles.

I wrote to André Simon, the author of Highlight, requesting this feature. Today I got an email from André informing me that the new 2.6.3 release of Highlight has an option to generate inline css! I tried it out and it works well.

$  highlight -i HelloWorld.java -o HelloWorld.html --inline-css

And here is the snippet Highlight generated for me:

public class HelloWorld {
    public static void main(String[] args) {
         System.out.println("Hello, World");
    }
}

Thanks and congratulations to André Simon!

Advertisements
Categories: blog, tech, wordpress
  1. September 7, 2007 at 1:06 am

    thank you binil. I was looking for an easy way to do the same. I’ve been using jEdit’s code2html for the same.

    I will try using this for my blog : anjanb.wordpress.com

    BR,
    ~A

  2. February 17, 2008 at 9:11 am

    useful, thanks!

  1. April 24, 2010 at 7:42 pm

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: