SyntaxHighlighting in Wordpress

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 (512) - 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.

5 Responses to “SyntaxHighlighting in Wordpress”

  1. Ziv says:

    Hey there,
    I’ve been looking for something like this for my website. The Download link isn’t working though, is there any chance you could fix it?
    Thanks,
    Ziv

  2. Ziv says:

    That didn’t work either, but I figured out the problem. When you try to Save As, it saves it by default as download.php, but the file is actually supposed to be a ZIP file. So you just have to append “.zip” to the end of the file name when saving.
    Thanks for the code!

    • Naatan says:

      Actually it does have the zip extension.. I’m guessing your browser reads it wrong because it says “.php.zip”.. shouldn’t be a problem with any normal browser (like Firefox).. I’m guessing you use IE.

  3. Ziv says:

    Nope, I use Firefox 2. Strange. Oh well, at least it’s working now =)

Leave a Reply

:) ;) :D :| :( :O :P