From e4702126ca8ee01714a13b0ed1df3b7adcd8b63f Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Wed, 14 Jan 2009 21:57:32 +0000 Subject: adjustments to auto_typography() to handle beginning and end lines that contain, but do not start/finish with block level elements. --- system/libraries/Typography.php | 31 +++++++++++++++++++++---------- user_guide/changelog.html | 1 + 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/system/libraries/Typography.php b/system/libraries/Typography.php index 3875bd5c4..11b3917c0 100644 --- a/system/libraries/Typography.php +++ b/system/libraries/Typography.php @@ -138,8 +138,13 @@ class CI_Typography { $str = ''; $process = TRUE; $paragraph = FALSE; + $current_chunk = 0; + $total_chunks = count($chunks); + foreach ($chunks as $chunk) - { + { + $current_chunk++; + // Are we dealing with a tag? If so, we'll skip the processing for this cycle. // Well also set the "process" flag which allows us to skip
 tags and a few other things.
 			if (preg_match("#<(/*)(".$this->block_elements.").*?>#", $chunk, $match))
@@ -163,17 +168,23 @@ class CI_Typography {
 				$str .= $chunk;
 				continue;
 			}
-
+			
+			//  Force a newline to make sure end tags get processed by _format_newlines()
+			if ($current_chunk == $total_chunks)
+			{
+				$chunk .= "\n";  
+			}
+			
 			//  Convert Newlines into 

and
tags $str .= $this->_format_newlines($chunk); } - - // is the whole of the content inside a block level element? - if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str, $match)) + + // No opening block level tag? Add it if needed. + if ( ! preg_match("/^\s*<(?:".$this->block_elements.")/i", $str)) { - $str = "

{$str}

"; + $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '

$1

<$2', $str); } - + // Convert quotes, elipsis, em-dashes, non-breaking spaces, and ampersands $str = $this->format_characters($str); @@ -185,7 +196,7 @@ class CI_Typography { // if '

{@HC1}' then replace

{@HC1}

with the comment, else replace only {@HC1} with the comment $str = preg_replace('#(?(?=

\{@HC'.$i.'\})

\{@HC'.$i.'\}(\s*

)|\{@HC'.$i.'\})#s', $html_comments[$i], $str); } - + // Final clean up $table = array( @@ -199,7 +210,7 @@ class CI_Typography { // Clean up stray paragraph tags that appear before block level elements '#

<('.$this->block_elements.')#' => '<$1', - + // Clean up stray non-breaking spaces preceeding block elements '#( \s*)+<('.$this->block_elements.')#' => ' <$2', @@ -223,7 +234,7 @@ class CI_Typography { // otherwise most browsers won't treat them as true paragraphs $table['#

#'] = '

 

'; } - + return preg_replace(array_keys($table), $table, $str); } diff --git a/user_guide/changelog.html b/user_guide/changelog.html index 1801a46b2..9de2b1fae 100644 --- a/user_guide/changelog.html +++ b/user_guide/changelog.html @@ -100,6 +100,7 @@ SVN Revision:

  • Fixed a bug where HTML comments and <pre> tags were being parsed in Typography::auto_typography().
  • Fixed a bug with non-breaking space cleanup in Typography::auto_typography().
  • Fixed a bug in database escaping where a compound statement (ie: SUM()) wasn't handled correctly with database prefixes.
  • +
  • Tweaked Typography::auto_typography() for some edge-cases.
  • -- cgit v1.2.3-24-g4f1b