diff --git a/include/bbcode.php b/include/bbcode.php index 10d33e8a5..369620038 100644 --- a/include/bbcode.php +++ b/include/bbcode.php @@ -1139,7 +1139,6 @@ function bbcode($Text, $options = []) { btlogger('Text is array: ' . print_r($Text,true)); } - $preserve_nl = ((array_key_exists('preserve_nl',$options)) ? $options['preserve_nl'] : false); $cache = ((array_key_exists('cache',$options)) ? $options['cache'] : false); $newwin = ((array_key_exists('newwin',$options)) ? $options['newwin'] : true); $export = ((array_key_exists('export',$options)) ? $options['export'] : false); @@ -1250,18 +1249,33 @@ function bbcode($Text, $options = []) { // Convert new line chars to html
tags $Text = str_replace("\r\n", "\n", $Text); - -// $Text = MarkdownExtra::DefaultTransform($Text); -// $Text = str_replace(">\n", '>
', $Text); - $Text = str_replace(array("\r", "\n"), array('
', '
'), $Text); - // if ($preserve_nl) - // $Text = str_replace(array("\n", "\r"), array('', ''), $Text); + // BEGIN markdown quirks + + $Text = str_replace('<br>','&_lt;br&_gt;', $Text); + + $Text = MarkdownExtra::DefaultTransform($Text); + + // linefeeds inside code blocks which were converted to
will have been converted to <br> by the default transform. + // convert them back to
. Those which were integral to the original code block before substitution have been escaped further + // and will be recovered after we perform this step. + + do { + $replaced = $Text; + $Text = preg_replace('/\(.*?)\<\;br\>\;(.*?)\<\/code\>/ism','$1
$2
',$Text); + } while ($replaced != $Text); + + // bbcode code blocks are wrapped in
. Do the same for markdown code blocks so that the styling is consistent
+		
+		$Text = str_replace([ '', '' ], [ '
', '
' ] , $Text); + + $Text = str_replace('&_lt;br&_gt;','<br>', $Text); + + // END markdown quirks $Text = str_replace(array("\t", " "), array("    ", "  "), $Text); - // Check for [code] text if (strpos($Text,'[code]') !== false) { $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism", 'bb_code', $Text);