Extend multi-line code blocks regular expression
- Covers the case where there's no new line after the [code] tag
This commit is contained in:
parent
3e56a63162
commit
f828afde83
|
@ -146,12 +146,16 @@ function bb2diaspora($Text, $preserve_nl = false, $fordiaspora = true) {
|
|||
|
||||
// Extracting multi-line code blocks before the whitespace processing/code highlighter in bbcode()
|
||||
$codeblocks = [];
|
||||
$Text = preg_replace_callback('#\[code(?:=([^\]]*))?\](?=\n)(.*?)\[\/code\]#is',
|
||||
function ($matches) use (&$codeblocks) {
|
||||
$return = '#codeblock-' . count($codeblocks) . '#';
|
||||
|
||||
$prefix = '````' . $matches[1] . PHP_EOL;
|
||||
$codeblocks[] = $prefix . trim($matches[2]) . PHP_EOL . '````';
|
||||
$Text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
|
||||
function ($matches) use (&$codeblocks) {
|
||||
$return = $matches[0];
|
||||
if (strpos($matches[2], "\n") !== false) {
|
||||
$return = '#codeblock-' . count($codeblocks) . '#';
|
||||
|
||||
$prefix = '````' . $matches[1] . PHP_EOL;
|
||||
$codeblocks[] = $prefix . trim($matches[2]) . PHP_EOL . '````';
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
, $Text);
|
||||
|
|
Loading…
Reference in a new issue