Fix nestable HTML, including <blockquote>'s. Props anonymousbugger (!) and Nazgul. fixes #1170

git-svn-id: http://svn.automattic.com/wordpress/trunk@5623 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
rob1n 2007-06-01 02:33:03 +00:00
parent 9e8bfa7f7b
commit b8c26df7e0

View File

@ -439,6 +439,8 @@ function balanceTags($text, $force = false) {
return $text;
$tagstack = array(); $stacksize = 0; $tagqueue = ''; $newtext = '';
$single_tags = array('br', 'hr', 'img', 'input'); //Known single-entity/self-closing tags
$nestable_tags = array('blockquote', 'div', 'span'); //Tags that can be immediately nested within themselves
# WP bug fix for comments - in case you REALLY meant to type '< !--'
$text = str_replace('< !--', '< !--', $text);
@ -489,11 +491,11 @@ function balanceTags($text, $force = false) {
if((substr($regex[2],-1) == '/') || ($tag == '')) {
}
// ElseIf it's a known single-entity tag but it doesn't close itself, do so
elseif ($tag == 'br' || $tag == 'img' || $tag == 'hr' || $tag == 'input') {
elseif ( in_array($tag, $single_tags) ) {
$regex[2] .= '/';
} else { // Push the tag onto the stack
// If the top of the stack is the same as the tag we want to push, close previous tag
if (($stacksize > 0) && ($tag != 'div') && ($tagstack[$stacksize - 1] == $tag)) {
if (($stacksize > 0) && !in_array($tag, $nestable_tags) && ($tagstack[$stacksize - 1] == $tag)) {
$tagqueue = '</' . array_pop ($tagstack) . '>';
$stacksize--;
}