From ee4585ec7170f66685a9487e1bf3032589907601 Mon Sep 17 00:00:00 2001 From: Hypolite Petovan Date: Thu, 14 Mar 2019 09:03:31 -0400 Subject: [PATCH] Add inline spans to code block extraction in BBCode::convert - Fixes autolinker replacing URLs inside of code spans --- src/Content/Text/BBCode.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 5474be98d..e417b38a4 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -1180,17 +1180,18 @@ class BBCode extends BaseObject return $return; }; - // Extracting multi-line code blocks before the whitespace processing + // Extracting code blocks before the whitespace processing and the autolinker $codeblocks = []; $text = preg_replace_callback("#\[code(?:=([^\]]*))?\](.*?)\[\/code\]#ism", function ($matches) use (&$codeblocks) { - $return = $matches[0]; + $return = '#codeblock-' . count($codeblocks) . '#'; if (strpos($matches[2], "\n") !== false) { - $return = '#codeblock-' . count($codeblocks) . '#'; - - $codeblocks[] = '
' . trim($matches[2], "\n\r") . '
'; + $codeblocks[] = '
' . trim($matches[2], "\n\r") . '
'; + } else { + $codeblocks[] = '' . $matches[2] . ''; } + return $return; }, $text @@ -1502,12 +1503,6 @@ class BBCode extends BaseObject // Check for font change text $text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm", "$2", $text); - // Declare the format for [code] layout - - $CodeLayout = '$1'; - // Check for [code] text - $text = preg_replace("/\[code\](.*?)\[\/code\]/ism", "$CodeLayout", $text); - // Declare the format for [spoiler] layout $SpoilerLayout = '
$1
';