summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDerek Jones <derek.jones@ellislab.com>2009-01-14 22:57:32 +0100
committerDerek Jones <derek.jones@ellislab.com>2009-01-14 22:57:32 +0100
commite4702126ca8ee01714a13b0ed1df3b7adcd8b63f (patch)
tree77b0aec1178a421dfa66ac0ce8d614fcb2d79b7f
parent162c0226ed81efa318be00f4b8bde44febadccde (diff)
adjustments to auto_typography() to handle beginning and end lines that contain, but do not start/finish with block level elements.
-rw-r--r--system/libraries/Typography.php31
-rw-r--r--user_guide/changelog.html1
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 <pre> 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 <p> and <br /> 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 = "<p>{$str}</p>";
+ $str = preg_replace("/^(.*?)<(".$this->block_elements.")/i", '<p>$1</p><$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 '<p>{@HC1}' then replace <p>{@HC1}</p> with the comment, else replace only {@HC1} with the comment
$str = preg_replace('#(?(?=<p>\{@HC'.$i.'\})<p>\{@HC'.$i.'\}(\s*</p>)|\{@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
'#<p></p><('.$this->block_elements.')#' => '<$1',
-
+
// Clean up stray non-breaking spaces preceeding block elements
'#(&nbsp;\s*)+<('.$this->block_elements.')#' => ' <$2',
@@ -223,7 +234,7 @@ class CI_Typography {
// otherwise most browsers won't treat them as true paragraphs
$table['#<p></p>#'] = '<p>&nbsp;</p>';
}
-
+
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: </p>
<li>Fixed a bug where HTML comments and &lt;pre&gt; tags were being parsed in Typography::auto_typography().</li>
<li>Fixed a bug with non-breaking space cleanup in Typography::auto_typography().</li>
<li>Fixed a bug in database escaping where a compound statement (ie: SUM()) wasn't handled correctly with database prefixes.</li>
+ <li>Tweaked Typography::auto_typography() for some edge-cases.</li>
</ul>