Page MenuHomePhabricator

D19767.diff
No OneTemporary

D19767.diff

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;
}
}

File Metadata

Mime Type
text/plain
Expires
Thu, May 9, 8:24 PM (3 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6276747
Default Alt Text
D19767.diff (2 KB)

Event Timeline