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:
Hypolite Petovan 2018-01-14 13:12:29 -05:00
parent 3e56a63162
commit f828afde83

View file

@ -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() // Extracting multi-line code blocks before the whitespace processing/code highlighter in bbcode()
$codeblocks = []; $codeblocks = [];
$Text = preg_replace_callback('#\[code(?:=([^\]]*))?\](?=\n)(.*?)\[\/code\]#is',
function ($matches) use (&$codeblocks) {
$return = '#codeblock-' . count($codeblocks) . '#';
$prefix = '````' . $matches[1] . PHP_EOL; $Text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#is",
$codeblocks[] = $prefix . trim($matches[2]) . PHP_EOL . '````'; 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; return $return;
} }
, $Text); , $Text);