diff --git a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php index 6a15fb9a52..edc6153d08 100644 --- a/src/applications/differential/parser/changeset/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/changeset/DifferentialChangesetParser.php @@ -27,7 +27,6 @@ class DifferentialChangesetParser { protected $parsedHunk = false; protected $filename = null; - protected $filetype = null; protected $missingOld = array(); protected $missingNew = array(); @@ -161,10 +160,7 @@ class DifferentialChangesetParser { public function setFilename($filename) { $this->filename = $filename; - if (strpos($filename, '.', 1) !== false) { - $parts = explode('.', $filename); - $this->filetype = end($parts); - } + return $this; } public function setHandles(array $handles) { @@ -723,7 +719,7 @@ class DifferentialChangesetParser { protected function getHighlightFuture($corpus) { return $this->highlightEngine->getHighlightFuture( - $this->filetype, + $this->highlightEngine->getLanguageFromFilename($this->filename), $corpus); } diff --git a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php index c0b3402547..3bf7e7ee3b 100644 --- a/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php +++ b/src/applications/diffusion/controller/file/DiffusionBrowseFileController.php @@ -179,13 +179,16 @@ class DiffusionBrowseFileController extends DiffusionController { list($text_list, $rev_list, $blame_dict) = $file_query->getBlameData(); - $highlightEngine = new PhutilDefaultSyntaxHighlighterEngine(); - $highlightEngine->setConfig( + $highlight_engine = new PhutilDefaultSyntaxHighlighterEngine(); + $highlight_engine->setConfig( 'pygments.enabled', PhabricatorEnv::getEnvConfig('pygments.enabled')); - $text_list = explode("\n", $highlightEngine->highlightSource($path, - implode("\n", $text_list))); + $text_list = explode( + "\n", + $highlight_engine->highlightSource( + $highlight_engine->getLanguageFromFilename($path), + implode("\n", $text_list))); $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, $needs_blame, $drequest, $file_query, $selected); diff --git a/src/applications/paste/controller/view/PhabricatorPasteViewController.php b/src/applications/paste/controller/view/PhabricatorPasteViewController.php index 776eacea5f..2809395853 100644 --- a/src/applications/paste/controller/view/PhabricatorPasteViewController.php +++ b/src/applications/paste/controller/view/PhabricatorPasteViewController.php @@ -89,14 +89,22 @@ class PhabricatorPasteViewController extends PhabricatorPasteController { require_celerity_resource('diffusion-source-css'); require_celerity_resource('syntax-highlighting-css'); - $highlightEngine = new PhutilDefaultSyntaxHighlighterEngine(); - $highlightEngine->setConfig( + $highlight_engine = new PhutilDefaultSyntaxHighlighterEngine(); + $highlight_engine->setConfig( 'pygments.enabled', PhabricatorEnv::getEnvConfig('pygments.enabled')); + + $language = $paste->getLanguage(); + if (empty($language)) { + $language = $highlight_engine->getLanguageFromFilename( + $paste->getTitle()); + } + $text_list = explode( - "\n", $highlightEngine->highlightSource( - nonempty($paste->getLanguage(), $paste->getTitle()), + "\n", + $highlight_engine->highlightSource( + $language, $file->loadFileData())); $rows = $this->buildDisplayRows($text_list);