diff --git a/conf/default.conf.php b/conf/default.conf.php index d01bdce229..f9ce1aa3a6 100644 --- a/conf/default.conf.php +++ b/conf/default.conf.php @@ -1081,12 +1081,16 @@ return array( // of classes which extend PhabricatorEventListener here. 'events.listeners' => array(), -// -- Pygments -------------------------------------------------------------- // +// -- Syntax Highlighting --------------------------------------------------- // - // Phabricator can highlight PHP by default, but if you want syntax - // highlighting for other languages you should install the python package - // 'Pygments', make sure the 'pygmentize' script is available in the - // $PATH of the webserver, and then enable this. + // Phabricator can highlight PHP by default and use Pygments for other + // languages if enabled. You can provide a custom highlighter engine by + // extending class PhutilSyntaxHighlighterEngine. + 'syntax-highlighter.engine' => 'PhutilDefaultSyntaxHighlighterEngine', + + // If you want syntax highlighting for other languages than PHP then you can + // install the python package 'Pygments', make sure the 'pygmentize' script is + // available in the $PATH of the webserver, and then enable this. 'pygments.enabled' => false, // In places that we display a dropdown to syntax-highlight code, diff --git a/src/applications/markup/PhabricatorMarkupEngine.php b/src/applications/markup/PhabricatorMarkupEngine.php index dbc85cc454..c5c2a4e105 100644 --- a/src/applications/markup/PhabricatorMarkupEngine.php +++ b/src/applications/markup/PhabricatorMarkupEngine.php @@ -90,6 +90,8 @@ class PhabricatorMarkupEngine { 'macros' => true, 'uri.allowed-protocols' => PhabricatorEnv::getEnvConfig( 'uri.allowed-protocols'), + 'syntax-highlighter.engine' => PhabricatorEnv::getEnvConfig( + 'syntax-highlighter.engine'), ); } @@ -106,6 +108,9 @@ class PhabricatorMarkupEngine { $options['uri.allowed-protocols']); $engine->setConfig('differential.diff', $options['differential.diff']); $engine->setConfig('header.generate-toc', $options['header.generate-toc']); + $engine->setConfig( + 'syntax-highlighter.engine', + $options['syntax-highlighter.engine']); $rules = array(); $rules[] = new PhutilRemarkupRuleEscapeRemarkup(); diff --git a/src/applications/markup/PhabricatorSyntaxHighlighter.php b/src/applications/markup/PhabricatorSyntaxHighlighter.php index 26ce6bca9e..5615207326 100644 --- a/src/applications/markup/PhabricatorSyntaxHighlighter.php +++ b/src/applications/markup/PhabricatorSyntaxHighlighter.php @@ -22,7 +22,7 @@ final class PhabricatorSyntaxHighlighter { public static function newEngine() { - $engine = new PhutilDefaultSyntaxHighlighterEngine(); + $engine = PhabricatorEnv::newObjectFromConfig('syntax-highlighter.engine'); $config = array( 'pygments.enabled' => PhabricatorEnv::getEnvConfig('pygments.enabled'), diff --git a/src/infrastructure/PhabricatorEnv.php b/src/infrastructure/PhabricatorEnv.php index 815f808a0a..9cd95510cd 100644 --- a/src/infrastructure/PhabricatorEnv.php +++ b/src/infrastructure/PhabricatorEnv.php @@ -316,6 +316,7 @@ final class PhabricatorEnv { 'mysql.implementation' => 'AphrontMySQLDatabaseConnectionBase', 'differential.attach-task-class' => 'DifferentialTasksAttacher', 'mysql.configuration-provider' => 'DatabaseConfigurationProvider', + 'syntax-highlighter.engine' => 'PhutilSyntaxHighlighterEngine', ); }