diff --git a/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php b/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php --- a/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php +++ b/src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php @@ -153,6 +153,11 @@ 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']); + } + if (empty($options['lang'])) { // If the user hasn't specified "lang=..." explicitly, try to guess the // language. If we fail, fall back to configured defaults. @@ -343,4 +348,18 @@ 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; + } + } diff --git a/src/infrastructure/markup/remarkup/__tests__/remarkup/interpreter-test.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/interpreter-test.txt --- a/src/infrastructure/markup/remarkup/__tests__/remarkup/interpreter-test.txt +++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/interpreter-test.txt @@ -30,9 +30,7 @@ Content: (content) Argv: (x=y) - - -
phutil_fake_test_block_interpreter {{{ content }}}
~~~~~~~~~~ Content: (content) Argv: (foo=bar) @@ -53,6 +51,4 @@ Content: (content) Argv: (x=y) - - -(No interpreter found: phutil_fake_test_block_interpreter) +phutil_fake_test_block_interpreter {{{ content }}}