diff --git a/html/inc/text_transform.inc b/html/inc/text_transform.inc index e07b936ffc..c349148497 100644 --- a/html/inc/text_transform.inc +++ b/html/inc/text_transform.inc @@ -104,12 +104,33 @@ function get_output_options($user) { // Converts bbcode to proper HTML // If $export is true, don't use BOINC CSS +// handle [pre] separately because we need to remove
s +// +function replace_pre($text, $export) { + if ($export) { + return preg_replace_callback( + "@\[pre\](.*?)\[/pre\]@is", + function ($matches) { + return "
".remove_br(substr($matches[0], 5, -6))."
"; + }, + $text + ); + } else { + return preg_replace_callback( + "@\[pre\](.*?)\[/pre\]@is", + function ($matches) { + return "
".remove_br(substr($matches[0], 5, -6))."
"; + }, + $text + ); + } +} + function bb2html($text, $export=false) { $urlregex = "(?:\"?)(?:(http\:\/\/)?)([^\[\"<\ ]+)(?:\"?)"; $httpsregex = "(?:\"?)https\:\/\/([^\[\"<\ ]+)(?:\"?)"; // List of allowable tags $bbtags = array ( - "@\[pre\](.*?)\[/pre\]@is", "@\[code\](.*?)\[/code\]@is", "@\[b\](.*?)\[/b\]@is", "@\[i\](.*?)\[/i\]@is", @@ -143,7 +164,6 @@ function bb2html($text, $export=false) { // What the above tags are turned in to if ($export) { $htmltags = array ( - "
\\1
", "\\1", "\\1", "\\1", @@ -172,7 +192,6 @@ function bb2html($text, $export=false) { ); } else { $htmltags = array ( - "
\\1
", "
\\1
", "\\1", "\\1", @@ -207,7 +226,8 @@ function bb2html($text, $export=false) { // $i<1000 to prevent DoS while ($text != $lasttext && $i<1000) { $lasttext = $text; - $text = preg_replace($bbtags,$htmltags,$text); + $text = replace_pre($text, $export); + $text = preg_replace($bbtags, $htmltags, $text); $i = $i + 1; } return $text;