@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Remarkup code blocks: guess language from "name="

Summary:
The file name is a sufficient source of information, if available.

Closes T15729

Test Plan: The new unit test is green. Old unit tests are green.

Reviewers: O1 Blessed Committers, avivey

Reviewed By: O1 Blessed Committers, avivey

Subscribers: avivey, tobiaswiese, Matthew, Cigaryno

Maniphest Tasks: T15729

Differential Revision: https://we.phorge.it/D25560

+26
+19
src/infrastructure/markup/blockrule/PhutilRemarkupCodeBlockRule.php
··· 153 153 return implode("\n", $out); 154 154 } 155 155 156 + // The name is usually a sufficient source of information for file ext. 157 + if (empty($options['lang']) && isset($options['name'])) { 158 + $options['lang'] = $this->guessFilenameExtension($options['name']); 159 + } 160 + 156 161 if (empty($options['lang'])) { 157 162 // If the user hasn't specified "lang=..." explicitly, try to guess the 158 163 // language. If we fail, fall back to configured defaults. ··· 341 346 'vba' => 1, 342 347 ); 343 348 return $map; 349 + } 350 + 351 + /** 352 + * Get the extension from a filename. 353 + * @param string "/path/to/something.name" 354 + * @return null|string ".name" 355 + */ 356 + private function guessFilenameExtension($name) { 357 + $name = basename($name); 358 + $pos = strrpos($name, '.'); 359 + if ($pos !== false) { 360 + return substr($name, $pos + 1); 361 + } 362 + return null; 344 363 } 345 364 346 365 }
+7
src/infrastructure/markup/remarkup/__tests__/remarkup/code-block-guess-from-name.txt
··· 1 + name=/etc/phpmyadmin/config.txt 2 + $lol = 1; 3 + ~~~~~~~~~~ 4 + <div class="remarkup-code-block" data-code-lang="txt" data-sigil="remarkup-code-block"><div class="remarkup-code-header">/etc/phpmyadmin/config.txt</div><pre class="remarkup-code">$lol = 1;</pre></div> 5 + ~~~~~~~~~~ 6 + name=/etc/phpmyadmin/config.txt 7 + $lol = 1;