Created
December 12, 2011 22:47
-
-
Save dmvk/1469505 to your computer and use it in GitHub Desktop.
FSHL block handler for texy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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