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

tomaszx’s picture

Category: feature » task
Status: Active » Reviewed & tested by the community

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.

havran’s picture

Status: Reviewed & tested by the community » Postponed

Maybe in next version. This need rewrite...