From 9da2ee9155eb8694f06a125ac1bec166e9071ac8 Mon Sep 17 00:00:00 2001 From: Rick Ellis Date: Tue, 23 Sep 2008 20:39:50 +0000 Subject: Fixed a bug that was adding too many blank paragraph tags under certain conditions --- system/libraries/Typography.php | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'system/libraries/Typography.php') diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 13b36dd64..76160bfe1 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -27,10 +27,10 @@ class CI_Typography { // Block level elements that should not be wrapped inside

tags - var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul'; + var $block_elements = 'p|div|blockquote|pre|code|h\d|script|ol|ul|dl|dt|dd'; // Elements that should not have

and
tags within them. - var $skip_elements = 'p|pre|ol|ul'; + var $skip_elements = 'p|pre|ol|ul|dl'; // Tags we want the parser to completely ignore when splitting the string. var $ignore_elements = 'a|b|i|em|strong|span|img|li'; @@ -154,7 +154,7 @@ class CI_Typography { '/()

/' => '$1', // )+#' => '

', + '#(

)+#' => '

', '/(

)+/' => '

', // Clean up stray paragraph tags that appear before block level elements @@ -260,11 +260,21 @@ class CI_Typography { { return $str; } - - $str = str_replace("\n\n", "

\n\n

", $str); + + // Convert two consecutive newlines to paragraphs + $str = str_replace("\n\n", "

\n\n

", $str); + + // Convert single spaces to
tags $str = preg_replace("/([^\n])(\n)([^\n])/", "\\1
\\2\\3", $str); - return '

'.$str.'

'; + // Wrap the whole enchilada in enclosing paragraphs + $str = '

'.$str.'

'; + + // Remove empty paragraphs if they are on the first line, as this + // is a potential unintended consequence of the previous code + $str = preg_replace("/

<\/p>(.*)/", "\\1", $str, 1); + + return $str; } // ------------------------------------------------------------------------ -- cgit v1.2.3-24-g4f1b