Wednesday, January 21, 2009

Perl syntax highlighting in Blogger

I did it! It took me a while but I managed to get Perl syntax highlighting for this Blogger blog!
Check out the end result:
#!/usr/bin/perl -w
# ----------------------------------------
# File : Skeleton.pl
# Author : DLP
# Date : January 18th 2009
# Object : Template for new script
# Known bugs : None
# To do : Nothing
# ----------------------------------------
my $PROG_NAME = "Skeleton";
my $VERSION = "v0.0.2";
my $PROG_DATE = "January 21st 2009";

print "This is $PROG_NAME $VERSION from $PROG_DATE.\n";

__END__
Jan 18 2009: first version of the Perl skeleton
Jan 21 2009: v0.0.2
- changed "used warnings" into -w on shebang line
- created global variables for program version info
Pretty neat, don't you think?
I tried for a long time to modify the blog's layout (in the Blogger menu, Customize->Layout->Edit Html) by manually inserting lines of code as described here ot there.
Both of these sites are using syntaxighlighter for different languages. It looked really good and I wanted it! Unfortunately, syntaxhighlighter does not support Perl (why?!!).
After much trial and post botching, I was getting frustrated. I would see a good result from Windows Internet Explorer but not from Firefox (problem also noticed by Soon Hui, see his blog).
I finally stumbled on Fazibear's post. He shared a Blogger widget that whould do all the dirty work for you. All you have to do is to install the widget from the Layout page. Then, when you have code to add to your post, you edit the Html and surround your code by:


your code
Simple and effective... except that Perl syntax would not get highlighted (see list of supported languages here).
Thankfully, there are always helpful souls on the web and Bear Den Designs's blog has posted the bit of javascript code that was missing from the syntax highlighter widget.
I just had to edit the Blogger Syntax Highliter widget and copy the extra code between the lines:

dp.sh.Highlighter();dp.sh.Brushes.JScript.Aliases=['js','jscript','javascript'];

dp.sh.Brushes.Ruby=function()
...

Et voilà!

French word of the day:
"Victoire!": Victory!

Next posts:
  • Perl development tools - Part II: setting up Notepad++
  • Our first Perl program - Part II: parsing the Perl command line
  • More about CPAN
  • Our first Perl program - Part III: Add a GUI interface
  • How to install Google Analytics on your Blogger blog
  • First version of FileInfo script

8 comments :

  1. Also had similar problem my WordPress blog. The syntaxhighlighter does come with WordPress but again no Perl and there appears to be no way to fix it like u did here ;-(

    So I just post my Perl code marked as "Ruby" and it works pretty well!

    /I3az/

    ReplyDelete
  2. That's a pretty smart way to do it!
    I don't know anything about Wordpress layouts so I won't help you here. During the past three nights when I was trying to get the syntaxhighlighter to work, I considered migrating to MovableType. This sounds like the right thing to do for a blog about Perl.
    Maybe one day...

    ReplyDelete
  3. Thanks for sharing this.

    Micky
    Perl CMS
    http://www.web-app.net/

    ReplyDelete
  4. If you're using wordpress there is a plugin (wp-syntax) that adds syntax highlighting for pretty much any programming language you can think of. It's based on the opensource project called geshi.

    http://wordpress.org/extend/plugins/wp-syntax/

    ReplyDelete
  5. Thanks a lot Damien. Consolidating all those links in one post really helped. You made my day!

    ReplyDelete
  6. This comment has been removed by a blog administrator.

    ReplyDelete