Extension:GeSHiHighlight

Note: There is a new GeSHi-highlighting extension for MediaWiki that I tried called GeSHiCodeTag and it works pretty well! And the guy also documented it very well.

The advantages of GeSHiHighlight over GeSHiColor are 1) it handles more langugages, 2) is still being maintained, and 3) seems to work better in general, although I can't vouch for that personally.

History (brief)
The pre tags in MediaWiki are nice, but they don't quite cut it for source code. With that in mind, I went questing for a syntax highlighting extension, and found "SyntaxHighlight" (http://www.wickle.com/wikis/index.php/Syntax_Highlight_extension) by Coffman, but I disagree with the use of two tags--one to specify you are in a code block, and another to specify the language: To get arround that, I hacked Coffman's 1.2 release to accept language tags: foreach(@myarr){print $_;} public class foo{ /* .... */ } That version is available here: ...... but I'm not planning on updating it again.

There is another drawback--SyntaxHighlight uses enscript, which (IMO) produces horrible results---better than just pre when dealing with source code, but I want more than comments, strings and keywords to be fontified.

Enter GeSHi.

MediaWiki and GeSHi
GeSHi (found here: http://qbnz.com/highlighter/index.php ) is a syntax highlighing library written in php. I'm new to php (and by new, I mean I wrote my first line of php code about 4 hours prior writing this--see above) and I was amazed at how easy it was to use GeSHi (this says nothing about my love/hate for php in general...).

Why GeSHi?
 * Better highlighting. Flat-out kicks enscript's ass.  I'm not fond of the default colors, but that can be dealt with later.
 * php. enscript, being an external program was writing files with md5hash names, which caused update issues when I was testing, command line params changed causing issues, not quite as elegant. (Using an external program was also my first inclination when thinking about this problem--I actually almost discarded GeSHi because of this narrow-mindedness.)
 * It seems to be actively developed. The release I'm using now is only about a week old.

So, where's the source? Here:

Yep, that's it. Bang. Pretty syntax highlighting with 28 language tags, for 28 languages (disclaimer: I haven't tested all these, and I have suspicions about html4strict working out of the box, but still.)

WARNING - Geshi not only adds tags like, etc. but also the tags  and. If you use divs in the wiki content, Geshi will highlight them and your pages may look incorrect. To fix this, after downloading GeSHi and unpacking it, rename files like geshi/div.php and geshi/css.php to something like geshi/divgeshi.php and geshi/cssgeshi.php

Now everything will look fine again. Naturally, if you do want to use the geshi div/css highlighters, you now have to enclose then in instead of

2nd November 2007
By HappyDog
 * Removed 'div' from the list of languages, as this ends up parsing any standard HTML &lt;div&gt; tags as code.
 * Fixed PHP notice-level error caused by missing quote marks around the $lang paramter in runtime-created function.

Installation

 * Install GeSHi per the GeSHi install instructions (link above)
 * Cut & paste the above code to a file called GeSHiHighlight.php
 * Put GeSHiHighlight.php in your MediaWiki installations' extensions folder
 * Add:  to LocalSettings.php

Further Links

 * m:User talk:Coffman/Geshi Syntax Highlight extension