Friday, November 19, 2010

Blogging Tips: Embed code segments in a blog post with SyntaxHighlighter

Have you ever wondered about how to include code segments in your blog post in a clear and neat manner like below? I did.
So I searched about how to achieve it and found that using SyntaxHighlighter is the secret.
public class HelloWorld {
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        System.out.println("Hello World");
    }
}
(Note: Please wait the page is fully loaded to view the above code with syntaxhighlighter)

It takes just a few minutes of configuration to add that feature to your blog as well. I was able to do it using following two references which describes step by step how to add syntaxhighlighter to your blog. Without reposting the same steps, I will share these references with you.
1. http://pleasemakeanote.blogspot.com/2008/06/posting-source-code-in-blogger.html
2. http://timbroder.com/2007/07/howto-post-code.html

Enjoy blogging..!

3 comments:

  1. Hi Hasi,
    I'm going to give a try to Prettify (http://code.google.com/p/google-code-prettify/), and will let you know how it goes. SyntaxHighlighter is of GNU Lesser General Public License and guess it won't be compatible with the license of my blog. Prettify is of Apache License 2.0, so my blog will be on the safer side. may be, we can compare the results after some time.:)

    Thank you.
    Regards,
    Kathiravelu Pradeeban.

    ReplyDelete
  2. Hi Pradeeban,

    Thanks for the comment, I really didn't think about the license. Good that pointed it out. Looking forward to see how it goes with 'Prettify' for you.

    Thanks,
    Hasini.

    ReplyDelete
  3. Hi there, I found your blog by the use of Google whilst searching for a comparable topic, your website came up, it seems to be good. I’ve bookmarked it in my google bookmarks.
    website design

    ReplyDelete

Note: Only a member of this blog may post a comment.