* Name: paragraph
* Purpose: convert \n and other newline chars to HTML paragraphs
* Note: Uses code from WordPress by Matthew Mullenweg (http://www.photomatt.net; http://www.wordpress.org)
* Input:
* - string: input block of text
* - br: change single \n to 'br' or not
* @param string
* @param string
* @return string|void
*/
function smarty_modifier_paragraph($string, $br=true) {
if($string != '') {
$string = $string . "\n"; // just to make things a little easier, pad the end
$string = preg_replace('|
\s*
|', "\n\n", $string);
$string = preg_replace('!(<(?:table|ul|ol|li|pre|form|blockquote|h[1-6])[^>]*>)!', "\n$1", $string); // Space things out a little
$string = preg_replace('!((?:table|ul|ol|li|pre|form|blockquote|h[1-6])>)!', "$1\n", $string); // Space things out a little
$string = preg_replace("/(\r\n|\r)/", "\n", $string); // cross-platform newlines
$string = preg_replace("/\n\n+/", "\n\n", $string); // take care of duplicates
$string = preg_replace('/\n?(.+?)(?:\n\s*\n|\z)/s', "\t
$1
\n", $string); // make paragraphs, including one at the end $string = preg_replace('|\s*?
|', '', $string); // under certain strange conditions it could create a P of entirely whitespace $string = preg_replace("|(
]*)>|i', "', $string); $string = preg_replace('!', '", $string); $string = str_replace('
\s*(?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)!', "$1", $string); $string = preg_replace('!(?(?:table|tr|td|th|div|ul|ol|li|pre|select|form|blockquote|p|h[1-6])[^>]*>)\s*
!', "$1", $string); if ($br) $string = preg_replace('|(?)\s*\n|', "