Posted by DrSlump on May 9, 2008 at 9:42pm
Jump to:
| Project: | Texy! |
| Version: | 6.x-1.0-beta1 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed |
Issue Summary
Here is a simple implementation for GeSHi:
require_once 'geshi/geshi.php';
if (!class_exists('GeSHi')) {
die('DOWNLOAD <a href="http://qbnz.com/highlighter/">GeSHi</a> AND UNPACK TO geshi FOLDER FIRST!');
}
/**
* User handler for code block
*
* @param TexyHandlerInvocation handler invocation
* @param string block type
* @param string text to highlight
* @param string language
* @param TexyModifier modifier
* @return TexyHtml
*/
function geshiBlockHandler($invocation, $blocktype, $content, $lang, $modifier) {
if ($blocktype !== 'block/code') {
return $invocation->proceed();
}
$lang = strtolower($lang);
if ($lang === 'js') $lang = 'javascript';
$texy = $invocation->getTexy();
$content = Texy::outdent($content);
$geshi = new GeSHi( $content, $lang );
$content = $geshi->parse_code();
$content = $texy->protect($content, TEXY_CONTENT_BLOCK); // or Texy::CONTENT_BLOCK in PHP 5
$elPre = TexyHtml::el('pre');
if ($modifier) $modifier->decorate($texy, $elPre);
$elPre->attrs['class'] = $lang;
$elCode = $elPre->create('code', $content);
return $elPre;
}
Comments
#1
Hi,
Thank you very much DrSlump.
This works great. I'm very hapy could use geshi with texy module.
But it's a pity that maintainer is to lazy to implement this code into texy module...
I understand, he not have a time but.. code is working and only put this to repo, no more.
#2
Maybe in next version. This need rewrite...