Here is a plugin that adds the GeSHi syntax highlighter to MODx. The plugin parses the document content, calling GeSHi every time it finds some code inside the <pre> ... </pre> tags.
You can define a default language for the highlighting, but also write code in another language with <pre language="otherLanguage"> ... </pre>.
You can see an example here:
http://www.dis.uniroma1.it/~allulli/index.php?id=21 (by the way, I have a styling problem with IE in this page, I will post a separate message about it).
There is also a snippet that does, more or less, the same of my plugin, and that was written concurrently by bll0:
http://modxcms.com/forums/index.php/topic,3579.0.html
And here are the plugin and the complete package:
Plugin Name: GeSHi
Description: GeSHI Syntax Highlighter
Event: OnWebPagePrerender
/**
* GeSHi Plugin 0.4 for MODx
* by Luca Allulli, April 2006
*
* Event: OnLoadWebDocument
*
* Based on the GeSHi highlighter at http://qbnz.com/highlighter/
*
* License: GNU GPL
*
*/
//Begin configuration
global $defaultGeshiLang;
$defaultGeshiLang="java5";
//End configuration
function replaceCodeBase($lang, $code) {
global $modx;
$path = $modx->config["base_path"].'assets/plugins/geshi/geshi/';
$geshi = new GeSHi($code, $lang, $path);
$geshi->set_header_type(GESHI_HEADER_PRE);
$geshi->set_tab_width(4);
return '<table width="100%"><tr><td>'.$geshi->parse_code().'</td></tr></table>';
}
function replaceCode($matches) {
global $defaultGeshiLang;
return replaceCodeBase($defaultGeshiLang, $matches[1]);
}
function replaceCodeLang($matches) {
return replaceCodeBase($matches[1], $matches[2]);
}
$e = &$modx->Event;
switch ($e->name) {
case "OnLoadWebDocument":
include_once($modx->config["base_path"].'assets/plugins/geshi/geshi.php');
$modx->documentObject['content']=preg_replace_callback("#<pre>(.*?)</pre>#s", "replaceCode", $modx->documentObject['content']);
$modx->documentObject['content']=preg_replace_callback("#<pre language=\"([^\"]*)\">(.*?)</pre>#s", "replaceCodeLang", $modx->documentObject['content']);
break;
default: // stop here
return;
break;
}
Edit: Version 0.4 stores the highlighted code into MODx cache.