Using SyntaxHighlighter to Format Code in WordPress

Based on a question in the StackOverflow beta site, I did some quick research into what are the best ways to perform syntax highlighting on code that is posted on blogs. Among the methods that were suggested (by myself or others):

  1. Hack together your own display logic to format it as you see fit
  2. Use the SyntaxHighlighter JavaScript library
  3. Use Windows Live Writer with the Insert Code plugin (I discuss that here)
  4. For WordPress, use the WP-Syntax plugin

Coincidentally, I had heard Scott Hanselman talking about how he does code formatting just a couple of days ago, in Hanselminutes #125, where he described how he posted code on his blog by putting it inside <pre></pre> tags, adding specific name and class attributes, and letting some JavaScript library do the formatting work. So I went to his blog, opened up a post with some code, and found my way to the SyntaxHighlighter JavaScript library. This is a very nifty library that handles formatting very nicely for a number of popular programming and scripting languages, and seemed to have a very easy implementation. So I decided to implement it for formatting code on my site.
Continue reading

Platypus

Take greasemonkey to the next level with platypus. From the site:

Platypus is a Firefox extension which lets you modify a Web page from your browser — “What You See Is What You Get” — and then save those changes as a Greasemonkey script so that they’ll be repeated the next time you visit the page. Editing pages to suit your needs is dandy — but making those changes “permanent” is the real payoff.

Some of the things you can do with Platypus include:

  • Remove parts of the page you don’t wish to see.
  • Move a part of the page to a different location.
  • Change the style and format of page elements.
  • Modify all the links on the page using a regular expression.
  • Insert your own HTML code.

For those of us (myself included) who have not taken the time to learn how to compose a greasemonkey script, here is an easy to use took that will do it for you.

Cool greasemonkey scripts that I am using

As I find start to use new ones, I’ll post them here

Also, if you want to know more about developing on greasemonkey, then dive into greasemonkey (.org).

Add persistent searches to Gmail with greasemonkey

See this blog post from persistent.info. It is a greasemonkey script that adds the ability to define and save persisten searches. Saved searches show up in a little orange box along the left side of the screen.

Gmail greasemonkey persisten searches

Uses cookies to track the “contents” of the searches and might need some page refreshing (I had to log out and log back in to get it to work). Very cool. See here for other Google and Gmail greasemonkey scripts.