Page MenuHomePhorge

D25299.1732393996.diff
No OneTemporary

D25299.1732393996.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
@@ -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

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)

Event Timeline