Jan 6, 2012 at 12:41am PST by Mike Pearl
Boy, isn't it a nightmare when you need to do something simple and there's no documentation out there? That's, unfortunately, the case with Joomla's core GeSHi plug-in. GeSHi is a nice, but simple syntax highlighter. So if you have the need to show your visitors a snippet of code, GeSHi makes it far more readable. Here's an example without GeSHi:
Here's an example using GeSHi:
<?php // Here are a few lines of Joomla code defined('_JEXEC') or die; function getBaseURI() { return JURI::base(); } ?>
A GeSHi plug-in comes neatly packaged with Joomla! right out of the box. As I said at the top, there's no good documentation out there. So, I cracked open the source code to figure it out. To make life a little easier for you, here's how to use it:
Out of the box, Joomla! disables the GeSHi plugin. Just like with any Joomla! plug-in, you've got to go to the Plug-in Manager, find it and Enable it for it to work. It's a Content plug-in and you can filter on GeSHi.
You'll need to tell GeSHi which code to highlight. Do that using the html <pre> tag, with a little twist. First, tell the GeSHi plugin which language you're using, with an xml:lang attribute. If you wish, you can follow that with a lines='true' attribute, which adds simple line numbers. That's all the core plugin supports. I almost forgot, the core plugin doesn't support all the languages, only the following:
Here are two examples:
Oh, one more thing. Since the <pre> tag shows contents as is, you may want to skip the new line after the <pre> tag and before the </pre> tag, like this:
<pre xml:php lines="true"><?php // Here are a few lines of Joomla code defined('_JEXEC') or die; function getBaseURI() { return JURI::base(); } ?></pre>