From 064a4a914f7d89ed0e5089f0d8d1d6ec9e39af8e Mon Sep 17 00:00:00 2001
From: Chris Fitch <cfitch@redcom.com>
Date: Thu, 17 Sep 2009 09:56:09 -0400
Subject: [PATCH] Fix line wrap regex for preformatted text


diff --git a/core/string_api.php b/core/string_api.php
index 3971dd2..f2b6614 100644
--- a/core/string_api.php
+++ b/core/string_api.php
@@ -106,7 +106,7 @@ function string_nl2br( $p_string, $p_wrap = 100 ) {
 				#     if other encoded characters are a problem
 				$piece = preg_replace( '/&nbsp;/', ' ', $piece );
 				if( ON == config_get( 'wrap_in_preformatted_text' ) ) {
-					$output .= preg_replace( '/([^\n]{' . $p_wrap . '})(?!<\/pre>)/', "$1\n", $piece );
+					$output .= preg_replace( '/([^\n]{' . $p_wrap . ',}?[\s]+)(?!<\/pre>)/', "$1\n", $piece );
 				} else {
 					$output .= $piece;
 				}
-- 
1.6.0.4

