Patch for balanceTags from Scott Reilly: http://mosquito.wordpress.org/view.php?id=53
git-svn-id: http://svn.automattic.com/wordpress/trunk@2057 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
acd814c90f
commit
a4857688db
|
@ -315,6 +315,7 @@ function funky_javascript_fix($text) {
|
||||||
@license GPL v2.0
|
@license GPL v2.0
|
||||||
@notes
|
@notes
|
||||||
@changelog
|
@changelog
|
||||||
|
--- Modified by Scott Reilly (coffee2code) 02 Aug 2004
|
||||||
1.2 ***TODO*** Make better - change loop condition to $text
|
1.2 ***TODO*** Make better - change loop condition to $text
|
||||||
1.1 Fixed handling of append/stack pop order of end text
|
1.1 Fixed handling of append/stack pop order of end text
|
||||||
Added Cleaning Hooks
|
Added Cleaning Hooks
|
||||||
|
@ -334,10 +335,10 @@ function balanceTags($text, $is_comment = 0) {
|
||||||
$text = preg_replace('#<([0-9]{1})#', '<$1', $text);
|
$text = preg_replace('#<([0-9]{1})#', '<$1', $text);
|
||||||
|
|
||||||
while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
|
while (preg_match("/<(\/?\w*)\s*([^>]*)>/",$text,$regex)) {
|
||||||
$newtext = $newtext . $tagqueue;
|
$newtext .= $tagqueue;
|
||||||
|
|
||||||
$i = strpos($text,$regex[0]);
|
$i = strpos($text,$regex[0]);
|
||||||
$l = strlen($tagqueue) + strlen($regex[0]);
|
$l = strlen($regex[0]);
|
||||||
|
|
||||||
// clear the shifter
|
// clear the shifter
|
||||||
$tagqueue = '';
|
$tagqueue = '';
|
||||||
|
@ -373,32 +374,46 @@ function balanceTags($text, $is_comment = 0) {
|
||||||
|
|
||||||
// Tag Cleaning
|
// Tag Cleaning
|
||||||
|
|
||||||
// Push if not img or br or hr
|
// If self-closing or '', don't do anything.
|
||||||
if($tag != 'br' && $tag != 'img' && $tag != 'hr') {
|
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') {
|
||||||
|
$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)) {
|
||||||
|
$tagqueue = '</' . array_pop ($tagstack) . '>';
|
||||||
|
$stacksize--;
|
||||||
|
}
|
||||||
$stacksize = array_push ($tagstack, $tag);
|
$stacksize = array_push ($tagstack, $tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Attributes
|
// Attributes
|
||||||
// $attributes = $regex[2];
|
|
||||||
$attributes = $regex[2];
|
$attributes = $regex[2];
|
||||||
if($attributes) {
|
if($attributes) {
|
||||||
$attributes = ' '.$attributes;
|
$attributes = ' '.$attributes;
|
||||||
}
|
}
|
||||||
$tag = '<'.$tag.$attributes.'>';
|
$tag = '<'.$tag.$attributes.'>';
|
||||||
|
//If already queuing a close tag, then put this tag on, too
|
||||||
|
if ($tagqueue) {
|
||||||
|
$tagqueue .= $tag;
|
||||||
|
$tag = '';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$newtext .= substr($text,0,$i) . $tag;
|
$newtext .= substr($text,0,$i) . $tag;
|
||||||
$text = substr($text,$i+$l);
|
$text = substr($text,$i+$l);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clear Tag Queue
|
// Clear Tag Queue
|
||||||
$newtext = $newtext . $tagqueue;
|
$newtext .= $tagqueue;
|
||||||
|
|
||||||
// Add Remaining text
|
// Add Remaining text
|
||||||
$newtext .= $text;
|
$newtext .= $text;
|
||||||
|
|
||||||
// Empty Stack
|
// Empty Stack
|
||||||
while($x = array_pop($tagstack)) {
|
while($x = array_pop($tagstack)) {
|
||||||
$newtext = $newtext . '</' . $x . '>'; // Add remaining tags to close
|
$newtext .= '</' . $x . '>'; // Add remaining tags to close
|
||||||
}
|
}
|
||||||
|
|
||||||
// WP fix for the bug with HTML comments
|
// WP fix for the bug with HTML comments
|
||||||
|
|
Loading…
Reference in New Issue