From d54078fff55f74ee4fd320b27f8129b48bdcd3fa Mon Sep 17 00:00:00 2001 From: admin Date: Fri, 20 Oct 2006 00:38:16 +0000 Subject: --- system/helpers/typography_helper.php | 72 +++++++++++++++++++++++++++++------- 1 file changed, 58 insertions(+), 14 deletions(-) (limited to 'system/helpers/typography_helper.php') diff --git a/system/helpers/typography_helper.php b/system/helpers/typography_helper.php index 65924f911..84ca0ed6f 100644 --- a/system/helpers/typography_helper.php +++ b/system/helpers/typography_helper.php @@ -129,7 +129,7 @@ class Auto_typography { * * We don't want quotes converted within * tags so we'll temporarily convert them to - * {{{DQ}}} and {{{SQ}}} + * {@DQ} and {@SQ} * */ if (preg_match_all("#\<.+?>#si", $str, $matches)) @@ -137,11 +137,24 @@ class Auto_typography { for ($i = 0; $i < count($matches['0']); $i++) { $str = str_replace($matches['0'][$i], - str_replace(array("'",'"'), array('{{{SQ}}}', '{{{DQ}}}'), $matches['0'][$i]), + str_replace(array("'",'"'), array('{@SQ}', '{@DQ}'), $matches['0'][$i]), $str); } } - + + + /* + * Add closing/opening paragraph tags before/after "block" elements + * + * Since block elements (like ,
, etc.) do not get
+		 * wrapped in paragraph tags we will add a closing 

tag just before + * each block element starts and an opening

tag right after the block element + * ends. Later on we'll do some further clean up. + * + */ + $str = preg_replace("#(<.*?)(".$this->block_elements.")(.*?>)#", "

\\1\\2\\3", $str); + $str = preg_replace("#(block_elements.")(.*?>)#", "\\1\\2\\3

", $str); + /* * Convert "ignore" tags to tempoarary marker * @@ -149,10 +162,10 @@ class Auto_typography { * it encounters. Certain inline tags, like image * tags, links, span tags, etc. will be adversely * affected if they are split out so we'll convert - * the opening < temporarily to: {{{tag}}} + * the opening < temporarily to: {@TAG} * - */ - $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{{{tag}}}\\1\\2", $str); + */ + $str = preg_replace("#<(/*)(".$this->ignore_elements.")#i", "{@TAG}\\1\\2", $str); /* * Split the string at every tag @@ -188,7 +201,7 @@ class Auto_typography { * 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)) 
 			{
 				if (preg_match("#".$this->skip_elements."#", $match['2']))
@@ -210,20 +223,51 @@ class Auto_typography {
 			$str .= $this->format_newlines($chunk);
 		}
 
+
+		/*
+		 * Clean up paragraph tags before/after "block" elements
+		 *
+		 * Earlier we added 

tags before/after block level elements. + * Then, we added paragraph tags around double line breaks. This + * potentially created incorrectly formatted paragraphs so we'll + * clean it up here. + * + */ + $str = preg_replace("#

({@TAG}.*?)(".$this->block_elements.")(.*?>)#", "\\1\\2\\3", $str); + $str = preg_replace("#({@TAG}/.*?)(".$this->block_elements.")(.*?>)

#", "\\1\\2\\3", $str); + // Convert Quotes and other characters $str = $this->format_characters($str); - - // We'll swap our temporary markers back and do some clean up. + + // Final clean up $str = preg_replace('#(

\n*

)#', '', $str); $str = preg_replace('#()

#', "\\1", $str); - + $str = str_replace( - array('

', '

', '{{{tag}}}', '{{{DQ}}}', '{{{SQ}}}'), - array('

', '

', '<', '"', "'"), + array( + '

', + '

', + '

', + '

', + '{@TAG}', + '{@DQ}', + '{@SQ}', + '

' + ), + array( + '

', + '

', + '

', + '

', + '<', + '"', + "'", + '' + ), $str - ); + ); - return trim($str); + return $str; } // -------------------------------------------------------------------- -- cgit v1.2.3-24-g4f1b