Extension:Syntax Highlighting



About 
The highlight syntax extension is a really simple way for you to add syntax highlighting to your wiki posts with support with several languages. The extension requires the Beautifier Syntax Highlighting Engine. What the extension does is pass the tag inputs and/or arguments to the Beautifier Highlighting engine and returns the HTML output.

Installation

 * 1) Download the Beautifier PHP Package from the Beautifier.org Site.
 * 2) *This is a dead link. But these mirrors work: mirrorservice planetmirror.
 * 3) *Use the php version which is partway down the list
 * 4) Extract the tarball somewhere on your remote server.  (I suggest to a subdirectory of your wiki directory named "beautifierpackage")
 * 5) *In the code he uses require_once("extensions/syntaxHighlightExtension.php"); so name your file as such "extensions/syntaxHighlightExtension.php".
 * 6) Copy all the text in the code section below into a new PHP file. (maybe you have to replace all &amp;lt; with < and &amp;gt; with >).
 * 7) Edit the $BEAUT_PATH, LOCAL_SERVER_ROOT, and $OUTPUT_HIGHLIGHT_AS to localize the extension for your system.
 * 8) Save the new PHP file to your server as syntaxHighlightExtension.php in your MediaWiki extension folder.
 * 9) Open the LocalSettings.php file in the root of your MediaWiki and add the following to the end of the file:

That's it! You're all installed. There are a lot of tweaks you can make to customize beautifier to make things simpler and add some new functions to their framework. Enjoy.

Improving the Highlighter
The output of the highlighter as downloaded from the beautifier web site contains hard coded colours even though the highlighter classes specify colours to use. I re-wrote the HTML outputter class in our installation to use the colours specified in the highlighter file.

To do the same you will need to pass the highlighter into the output class by changing the line to

And then replace the Output_HTML class in Output\Output_HTML.php with the following.

This only changes the HTML outputter, to change the CSS one in a similar fashion would be more complex since it relies on CSS classes to provide the different formatting. I guess you could write these classes out at the start of the block, but I'm not sure how the browser would react to having the styles redefined if you included multiple blocks using different languages.

Inline Highlighting
PHP Code

Code in a specific language

Highlight a file on your local server
or