Skip to content

Instantly share code, notes, and snippets.

@dmvk
Created December 12, 2011 22:47
Show Gist options
  • Save dmvk/1469505 to your computer and use it in GitHub Desktop.
Save dmvk/1469505 to your computer and use it in GitHub Desktop.
FSHL block handler for texy
<?php
namespace Moes\Texy;
class FSHLHandler
{
public function __invoke($invocation, $blocktype, $content, $lang, $modifier)
{
if ($blocktype !== 'block/code')
return $invocation->proceed();
$lang = strtolower($lang);
if ($lang === 'js')
$lang = 'javascript';
$lexer = '\FSHL\Lexer\\' . ucfirst($lang);
if (!class_exists($lexer))
return $invocation->proceed();
$fshl = new \FSHL\Highlighter(new \FSHL\Output\Html);
$fshl->setLexer(new $lexer);
$texy = $invocation->getTexy();
$content = \Texy::outdent($content);
$content = $fshl->highlight($content);
$content = $texy->protect($content, \Texy::CONTENT_BLOCK);
$pre = \TexyHtml::el('pre');
if ($modifier) $modifier->decorate($texy, $pre);
$pre->attrs['class'] = strtolower($lang);
$pre->create('code', $content);
return $pre;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment