SyntaxHighlighting in Wordpress

November 20th, 2008

Syntaxhighlighter PluginOne of the first plugins I installed on my new blog is the SyntaxHighlighter plugin by matt, Viper007Bond and mdawaffe, from what I understand each of these guys kind of perfected the other persons version.

Anyway, the plugin is great, it basically just incorporates the Syntaxhighlighter script by Alex Gorbatchev into Wordpress. There’s just one problem though, it does not support indentation, as the TinyMCE configuration in Wordpress doesn’t convert spaces to &nbsp;’s. Also tags like <?php were in my case converted to &lt;?php, which is quite annoying.

Long story short, I’ve done some playing around with the code and it turns out that just by removing the TinyMCE encoding / decoding functions and adding a small function to convert spaces to &nbsp;’s this plugin works great!


<?php
    echo 'Proof! Look.. I can use &nbsp; as plain text as well.. ';
?>

Attached to this post is the modified syntaxhighlighter.php file, just install the SyntaxHighlighter plugin and replace the syntaxhighlighter.php with the one posted underneath.

Download: syntaxhighlighter.php (511) - 3.88 KB

I’d like to give some quick kudo’s to Steve Smith from The Wordpress Magazine for sharing his SyntaxHighlighter modifications with me, without them it would have taken me much longer to figure this one out.