Page MenuHomePhorge

D25560.1734655760.diff
No OneTemporary

D25560.1734655760.diff

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/code-block-guess-from-name.txt b/src/infrastructure/markup/remarkup/__tests__/remarkup/code-block-guess-from-name.txt
new file mode 100644
--- /dev/null
+++ b/src/infrastructure/markup/remarkup/__tests__/remarkup/code-block-guess-from-name.txt
@@ -0,0 +1,7 @@
+ name=/etc/phpmyadmin/config.txt
+ $lol = 1;
+~~~~~~~~~~
+<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>
+~~~~~~~~~~
+name=/etc/phpmyadmin/config.txt
+ $lol = 1;

File Metadata

Mime Type
text/plain
Expires
Fri, Dec 20, 00:49 (18 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1016292
Default Alt Text
D25560.1734655760.diff (1 KB)

Event Timeline