Project Development: How to Highlight the Source Code in Blogger:

Friday, December 3, 2010

How to Highlight the Source Code in Blogger:

I had been through a lot for searching the solution to highlight the source code in my Blogger.

This was also the reason I give up on the use of Blogger.

Then I move to here, which has a fine support of highlighting source code;

Here is the step to follow:


  1. Open your source code with vi or vim;
  2. Set the line number :set nu (optional)
  3. Convert your source code to html file :TOhtml
  4. Copy and Paste the converted code, which is located between body tags.
  5. Before publish your post, check your post options. Choose use <br /> tags as the html line breaks, and check the compose settings as show HTML literally.
  6. Unset the line number :set nonu (optional)
  7. Update: recently I add -c 'syntax on' which could help MAC user to have their syntax highlighted.

Here is a bash script to help your conversion.

#!/bin/sh

for i in $*
do

 vim -c ':set nonu' -c ':syntax on' -c ':TOhtml' -c ':w' -c ':q' -c ':q' $i

done

Hope this works for you.