From: Hypolite Petovan Date: Sun, 14 Jan 2018 18:12:29 +0000 (-0500) Subject: Extend multi-line code blocks regular expression X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=f828afde8356108b0759dcc38af0689ccef93008;p=friendica.git Extend multi-line code blocks regular expression - Covers the case where there's no new line after the [code] tag --- diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index 714d780048..daa8c5e048 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -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', + + $Text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is", function ($matches) use (&$codeblocks) { - $return = '#codeblock-' . count($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 . '````'; + $prefix = '````' . $matches[1] . PHP_EOL; + $codeblocks[] = $prefix . trim($matches[2]) . PHP_EOL . '````'; + } return $return; } , $Text);