Hello,
this collection includes and integrates three useful plugins for mathematicians, computer scientists etc. (you can use only those plugins you really need, of course):
- The GeSHi plugin, to highlight source code in your document;
- The mimeTeX plugin, to insert and render LaTeX code;
- The Textile Plus plugin, to prepare easily the page content. Based on the Textile plugin by Raymond Irving and Jens Theess.
The textile plugin is particularly important because Rich Text Editors don’t behave well with source code, and thus are not compatible with GeSHi and mimeTeX.
The plugins are very efficient: they are invoked only when the webpage is retrieved from the database, and then a parsed version of the page is saved in cache.
The package has everything you need, except the mimeTeX cgi program, that you can download from their website.
For more information about these plugins, please refer to the forum threads where they were originally posted:
A few more words about Textile Plus: there are a couple of differences with respect to the original Textile plugin, namely:
it parses only the [*content*] field of your document, and only when the page is retrieved from the database (for efficiency reasons: the parsed page is saved in cache);
it doesn’t parse the code enclosed into <textsafe>...</textsafe> tags. This is useful to insert raw code (e.g. HTML) inside a textile document. An additional plugin provided in the package automatically inserts GeSHi and mimeTeX code that occurs in <textile> mode into <textsafe> tags, and thanks to it Textile behaves nicely with GeSHi and mimeTeX.
Here is the plugin code; let it listen to the OnLoadWebDocument event.
// <?
/**
* Textile AutoSafe Plugin 0.1 for MODx
* by Luca Allulli, April 2006
*
* Event: OnLoadWebDocument
*
* License: GNU GPL
*
*/
//Begin configuration
//End configuration
function replaceTextileCloseTagsInternal($matches) {
return '<textsafe>'.$matches[1].'</textsafe>';
}
function replaceTextileCloseTags($matches) {
$modvar = preg_replace_callback("#(<pre[^>]*>.*?</pre>)#s", "replaceTextileCloseTagsInternal", $matches[1]);
$modvar = preg_replace_callback("#(\\$\\$.*?\\$\\$)#s", "replaceTextileCloseTagsInternal", $modvar);
return '<textile>'.$modvar.'</textile>';
}
$e = &$modx->Event;
switch ($e->name) {
case "OnLoadWebDocument":
$modx->documentObject['content']=preg_replace_callback("#<textile>(.*?)</textile>#s", "replaceTextileCloseTags", $modx->documentObject['content']);
break;
default: // stop here
break;
}
/**
* Textile Plus Plugin 0.1 for MODx
* by Luca Allulli, April 2006
* Based on the Textile Plugin by Raymond Irving and Jens Theess
*
* Event: OnLoadWebDocument
*
* License: GNU GPL
*
*/
//Begin configuration
//End configuration
function replaceCodeTextileHtml($matches) {
global $textileSafeCode;
global $textileSafeCodeCount;
if(!isset($textileSafeCodeCount))
$textileSafeCodeCount=0;
else
$textileSafeCodeCount++;
$textileSafeCode[$textileSafeCodeCount] = $matches[1];
return('<TextileSafeCode_'.$textileSafeCodeCount.'>');
}
function replaceCodeTextileHtmlBack($matches) {
global $textileSafeCode;
return $textileSafeCode[$matches[1]];
}
function replaceCodeTextile($matches) {
global $textileParser;
$modtext = preg_replace_callback("#<textsafe>(.*?)</textsafe>#s", "replaceCodeTextileHtml", $matches[1]);
$modtext = $textileParser -> TextileThis($modtext);
return preg_replace_callback("#\\<TextileSafeCode_([^>]*)>#s", "replaceCodeTextileHtmlBack", $modtext);
}
$modtext = preg_replace_callback("#<textsafe>(.*?)</textsafe>#s", "replaceCodeTextileHtml", $matches[1]);
include_once($modx->config["base_path"].'/assets/plugins/textile/classTextile.php');
global $textileParser;
$textileParser = new Textile();
$e = &$modx->Event;
switch ($e->name) {
case "OnLoadWebDocument":
$modx->documentObject['content']=preg_replace_callback("#<textile>(.*?)</textile>#s", "replaceCodeTextile", $modx->documentObject['content']);
break;
default: // stop here
break;
}
/**
* GeSHi Plugin 0.4 for MODx
* by Luca Allulli, March 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
break;
}
/**
* mimeTeX Plugin 0.1 for MODx
* by Luca Allulli, April 2006
*
* Event: OnLoadWebDocument
*
* Download and install mimeTeX from http://www.forkosh.com/mimetex.html
*
* License: GNU GPL
*
*/
//Begin configuration
global $mimetexPath;
$mimetexPath="/cgi-bin/mimetex.cgi";
//End configuration
function replaceCodeMimetex($matches) {
global $mimetexPath;
return '<img src="'.$mimetexPath.'?'.$matches[1].'" align="middle" style="margin-bottom: 7px;" />';
}
$e = &$modx->Event;
switch ($e->name) {
case "OnLoadWebDocument":
$modx->documentObject['content']=preg_replace_callback("#\\$\\$(.*?)\\$\\$#s", "replaceCodeMimetex", $modx->documentObject['content']);
break;
default: // stop here
break;
}
// ?>