I spent Thursday whipping up my very first WordPress plugin (and yesterday plus today fixing its first bugs). It’s called Phi (as in the Greek letter φ), which stands for PHP Highlight. It’s currently running in this blog, and so far it’s been working really well for me. I don’t enjoy syntax highlighting for anything but PHP, but I’m happy.
I tried a few plugins like WP-Syntax and SyntaxHighlighter Plus, however they were too complicated and feature-rich for my needs, and recent versions of WP-Syntax, which I’d been using for the past year, were beginning to mess with my styles. That annoyed me real good. Plus, GeSHi colors were getting a little boring for me.
There was WP-Syntax Colorizer, but it didn’t quite satisfy me.
That does it, I thought. So I set out to put together a simple plugin which would fulfill my needs, using PHP’s humble highlight_string() function (PHP manual page).
And Phi was born.
I might release Phi soon. I believe there are others out there who share my opinion about the bigger syntax highlighting plugins. Besides, this is my first, so for additional kicks I’d like to see what it’s like to be a proud developer of my very own WordPress plugin (heh).
Here’s an excerpt of Phi’s source code, highlighted using Phi itself of course:
Example 1: Phi’s source code, highlighted using Phi
<?php
// PHP 4 coughs up <font> tags - clearly highly undesirable behavior
if ( version_compare(phpversion(), '5.0.0', '<') ) {
$php = preg_replace(
array('@<font color="(.+?)">@', '@</font>@'),
array('<span style="color: $1">', '</span>'),
$php
);
}
?>
See also, at dev.NOVALISTIC, Phi in action.
Join in the discussion
XHTML: You can use these tags:
<a href="" title=""><abbr title=""><acronym title=""><b><blockquote cite=""><cite><code><del datetime=""><em><i><q cite=""><strike><strong>Your comment content is limited to between 0 words and 300 words long.