2011-07-06 21:12:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group markup
|
|
|
|
*/
|
|
|
|
final class PhabricatorSyntaxHighlighter {
|
|
|
|
|
|
|
|
public static function newEngine() {
|
2012-06-27 04:06:53 +02:00
|
|
|
$engine = PhabricatorEnv::newObjectFromConfig('syntax-highlighter.engine');
|
2011-07-06 21:12:17 +02:00
|
|
|
|
|
|
|
$config = array(
|
|
|
|
'pygments.enabled' => PhabricatorEnv::getEnvConfig('pygments.enabled'),
|
|
|
|
'filename.map' => PhabricatorEnv::getEnvConfig('syntax.filemap'),
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($config as $key => $value) {
|
|
|
|
$engine->setConfig($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function highlightWithFilename($filename, $source) {
|
|
|
|
$engine = self::newEngine();
|
|
|
|
$language = $engine->getLanguageFromFilename($filename);
|
2012-04-13 08:52:50 +02:00
|
|
|
return $engine->highlightSource($language, $source);
|
2011-07-06 21:12:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static function highlightWithLanguage($language, $source) {
|
|
|
|
$engine = self::newEngine();
|
2012-04-13 08:52:50 +02:00
|
|
|
return $engine->highlightSource($language, $source);
|
2011-07-06 21:12:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|