Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2682361
D25560.1734655760.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
D25560.1734655760.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D25560: Remarkup code blocks: guess language from "name="
Attached
Detach File
Event Timeline
Log In to Comment