Sunday, November 28, 2010

Bounced back to blogspot

#!/usr/bin/perl
use strict;
use warnings;
print "Because you cannot install plugins on wordpress.com blogs";
print "Which means I cannot install this cool plugin which";
print "lets me indent and syntax highlight my Perl code\n";
exit(0);

Wordpress.com has the <code> tag - which for the average programmer means that I can use this tag to copy paste my code on the blog and it will show up all nice and indented. But from the usage, code tag just "encodes" HTML i.e. you don't need to escape < tag in #include <stdio.h>

The code tag doesn't indent. It doesn't highlight. It just converts the text to code font. The forums tell you to post your code in pre tags. Pre tags work but not always. As per Shuvam's comment below - the quirk might be with the specific template I am working with. So I created a test page on wordpress -

Test page to check code layout on wordpress.com

and tried it out with a 10-15 initial templates. None of them did the trick. I am not going to try out the 100+ templates that they offer and neither would I compromise on the rest of the layout just because some theme shows the pre tags cleanly.

If you are thinking blockquote - that converts my text to italics, doesn't indent and I sure wouldn't want my code to be displayed in italics.

And for the ones who are thinking - why don't you search a code snippet plugin and install it? - I can't. Wordpress.com won't let me. You cannot install plugins on wordpress.com blogs because of security reasons. If you want to install plugins and I am sure there are plenty of good ones available - use wordpress.org. For which you need someone to host your site for you. And I don't want to do that.

To know the complete difference between hosting on wordpress.com and wordpress.org - read this

There is a plugin Syntax Highlighter which does the above magic, the only limitation being that it currently does not support Perl.

But there is a fix for that also. This post by Damien made me jump back to blogspot. Goes to show how important it is to share your findings with others.

Blogspot does not give as many themes as wordpress.com but at least I can choose the one I want and use the SyntaxHighlighter plugin with it.

Sad. I was hoping to play more on wordpress. But I am going to paste inline code in my future posts and I can't stand intentionally unindented code.

5 comments:

shuvam said...

Are you sure the problem is Wordpress specific, not theme-specific? I thought the entire control of appearance of the article is in the hands of the theme. Would switching to a different theme have fixed the problem?

If not, then of course I agree no techie will use Wordpress -- without our code, we are powerless.

Saurabh said...

@shuvam - From what google told me, I think the problem is wordpress specific. If I had a hosted site, I would be able to install the SyntaxHighlighter plugin which requires an ftp of the plugin to the target server. The closest I can get is to write raw HTML using div to hold my code. And doing that for every small snippet is a pain. I will check switching themes and update this comment thread. But the very thought of being unable to install plugins puts me off.

shuvam said...

So this is not a Wordpress (the software) problem -- it seems to be a Wordpress.com (the hosting service) problem. Do you want to try commercial hosting? There are excellent third-party hosting services, including the very popular and inexpensive GoDaddy.com... a lot of serious bloggers seem to have shifted to such hosting services specifically to tackle the need of adding plugins, download additional themes, edit the theme, etc, freely. (Wordpress.com does not allow you to upload your own theme.)

Saurabh said...

@shuvam - Blogspot lets me do all of this for free. I can upload custom theme templates, add/remove plugins easily here. I think I'd rather grow more on the consistency of posting and building a good audience for my works. If I hit a requirement which I think blogspot can't satisfy I will definitely consider commercial hosting as a solution.

Anonymous said...

Syntax Highlighter does support Perl, I use it happily on my wordpress blog. It lacks some other features, though, like the ability to set the starting line number (so you can always address the code by the absolute line number), but finally it supports Perl - it didn't some time ago, I used to use "ruby" (yeah, I know, blasphemy) in those dark ages ;-)