From f828afde8356108b0759dcc38af0689ccef93008 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Sun, 14 Jan 2018 13:12:29 -0500 Subject: [PATCH] Extend multi-line code blocks regular expression - Covers the case where there's no new line after the [code] tag --- include/bb2diaspora.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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); -- 2.39.5