Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2648082
D25299.1732393996.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
D25299.1732393996.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
@@ -44,11 +44,18 @@
}
public function markupText($text, $children) {
- if (preg_match('/^\s*```/', $text)) {
+ $very_first_line = null;
+ if (preg_match('/^\s*```(.*)/', $text, $matches)) {
// If this is a ```-style block, trim off the backticks and any leading
// blank line.
$text = preg_replace('/^\s*```(\s*\n)?/', '', $text);
$text = preg_replace('/```\s*$/', '', $text);
+
+ // Just after the opening backticks there can be something valuable.
+ // Note that the general options are not necessarily here.
+ if (isset($matches[1])) {
+ $very_first_line = $matches[1];
+ }
}
$lines = explode("\n", $text);
@@ -79,6 +86,17 @@
}
}
+ // If explicitly missing, eventually parse the language expressed
+ // just after the first backticks.
+ // Skip one-line blocks, to do not eat potential one-line content.
+ // If found, we remove that line since it is not content.
+ if (empty($options['lang']) && $very_first_line && count($lines) > 1) {
+ if (preg_match('/^[a-z0-9\-\+\#\/]+$/', $very_first_line)) {
+ $options['lang'] = $very_first_line;
+ array_shift($lines);
+ }
+ }
+
// Normalize the text back to a 0-level indent.
$min_indent = 80;
foreach ($lines as $line) {
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 23, 20:33 (18 h, 47 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
991828
Default Alt Text
D25299.1732393996.diff (1 KB)
Attached To
Mode
D25299: Remarkup Code-block: parse language specifier in markdown
Attached
Detach File
Event Timeline
Log In to Comment