1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-16 11:52:40 +01:00
phorge-phorge/src/infrastructure/markup/PhabricatorSyntaxHighlighter.php

36 lines
885 B
PHP
Raw Normal View History

<?php
/**
* @group markup
*/
final class PhabricatorSyntaxHighlighter {
public static function newEngine() {
$engine = PhabricatorEnv::newObjectFromConfig('syntax-highlighter.engine');
$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);
return $engine->highlightSource($language, $source);
}
public static function highlightWithLanguage($language, $source) {
$engine = self::newEngine();
return $engine->highlightSource($language, $source);
}
}