diff --git a/src/markup/engine/remarkup/blockrule/PhutilRemarkupCodeBlockRule.php b/src/markup/engine/remarkup/blockrule/PhutilRemarkupCodeBlockRule.php --- a/src/markup/engine/remarkup/blockrule/PhutilRemarkupCodeBlockRule.php +++ b/src/markup/engine/remarkup/blockrule/PhutilRemarkupCodeBlockRule.php @@ -120,11 +120,18 @@ // If the user hasn't specified "lang=..." explicitly, try to guess the // language. If we fail, fall back to configured defaults. $lang = PhutilLanguageGuesser::guessLanguage($text); + + if (!$lang && $options['name']) { + $lang = $this->getHighlighterEngine() + ->getLanguageFromFilename($options['name']); + } + if (!$lang) { $lang = nonempty( $this->getEngine()->getConfig('phutil.codeblock.language-default'), 'text'); } + $options['lang'] = $lang; } @@ -230,14 +237,6 @@ .'em; overflow: auto;'; } - $engine = $this->getEngine()->getConfig('syntax-highlighter.engine'); - if (!$engine) { - $engine = 'PhutilDefaultSyntaxHighlighterEngine'; - } - $engine = newv($engine, array()); - $engine->setConfig( - 'pygments.enabled', - $this->getEngine()->getConfig('pygments.enabled')); return phutil_tag( 'pre', array( @@ -246,7 +245,26 @@ ), PhutilSafeHTML::applyFunction( 'rtrim', - $engine->highlightSource($options['lang'], $text))); + $this->getHighlighterEngine() + ->highlightSource($options['lang'], $text))); + } + + private function getHighlighterEngine() { + $engine = $this->getEngine()->getConfig('syntax-highlighter.engine'); + + if (!$engine) { + $engine = 'PhutilDefaultSyntaxHighlighterEngine'; + } + + $engine = newv($engine, array()); + $engine->setConfig( + 'pygments.enabled', + $this->getEngine()->getConfig('pygments.enabled')); + $engine->setConfig( + 'filename.map', + $this->getEngine()->getConfig('filename.map')); + + return $engine; } }