Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F13178424
D19767.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D19767.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D19767: Infer language from filename in Remarkup code blocks
Attached
Detach File
Event Timeline
Log In to Comment