GeSHi syntax highlighting handler

DrSlump - May 9, 2008 - 21:42
Project:Texy!
Version:6.x-1.0-beta1
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:postponed
Description

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;
}

#1

tomaszx - May 28, 2008 - 11:02
Category:feature request» 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.

#2

havran - April 16, 2009 - 11:04
Status:reviewed & tested by the community» postponed

Maybe in next version. This need rewrite...

 
 

Drupal is a registered trademark of Dries Buytaert.