Changeset View
Changeset View
Standalone View
Standalone View
src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
Show First 20 Lines • Show All 147 Lines • ▼ Show 20 Lines | if ($this->getEngine()->isTextMode()) { | ||||
} | } | ||||
$text = preg_replace('/^/m', ' ', $text); | $text = preg_replace('/^/m', ' ', $text); | ||||
$out[] = $text; | $out[] = $text; | ||||
return implode("\n", $out); | return implode("\n", $out); | ||||
} | } | ||||
// The name is usually a sufficient source of information for file ext. | |||||
if (empty($options['lang']) && isset($options['name'])) { | |||||
$options['lang'] = $this->guessFilenameExtension($options['name']); | |||||
} | |||||
avivey: Better move this into the `if (empty($options['lang'])))` block below. | |||||
Done Inline Actions(Premising that it was a feature - kind of waterfall attempt - since guessFilenameExtension() can return NULL) valerio.bozzolan: (Premising that it was a feature - kind of waterfall attempt - since `guessFilenameExtension()`… | |||||
if (empty($options['lang'])) { | if (empty($options['lang'])) { | ||||
// If the user hasn't specified "lang=..." explicitly, try to guess the | // If the user hasn't specified "lang=..." explicitly, try to guess the | ||||
// language. If we fail, fall back to configured defaults. | // language. If we fail, fall back to configured defaults. | ||||
$lang = PhutilLanguageGuesser::guessLanguage($text); | $lang = PhutilLanguageGuesser::guessLanguage($text); | ||||
if (!$lang) { | if (!$lang) { | ||||
$lang = nonempty( | $lang = nonempty( | ||||
$this->getEngine()->getConfig('phutil.codeblock.language-default'), | $this->getEngine()->getConfig('phutil.codeblock.language-default'), | ||||
'text'); | 'text'); | ||||
▲ Show 20 Lines • Show All 174 Lines • ▼ Show 20 Lines | static $map = array( | ||||
'sh' => 1, | 'sh' => 1, | ||||
'sql' => 1, | 'sql' => 1, | ||||
'typescript' => 1, | 'typescript' => 1, | ||||
'vba' => 1, | 'vba' => 1, | ||||
); | ); | ||||
return $map; | return $map; | ||||
} | } | ||||
/** | |||||
* Get the extension from a filename. | |||||
* @param string "/path/to/something.name" | |||||
* @return null|string ".name" | |||||
*/ | |||||
private function guessFilenameExtension($name) { | |||||
$name = basename($name); | |||||
$pos = strrpos($name, '.'); | |||||
if ($pos !== false) { | |||||
return substr($name, $pos + 1); | |||||
} | |||||
return null; | |||||
} | |||||
} | } |
Content licensed under Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) unless otherwise noted; code licensed under Apache 2.0 or other open source licenses. · CC BY-SA 4.0 · Apache 2.0
Better move this into the if (empty($options['lang']))) block below.