From: Duncan Beevers Date: Tue, 2 Sep 2014 04:26:39 +0000 (-0500) Subject: Push tag and attrs to stack X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=355ec734d3aa39e4281d02a9a7b2bb1e1a5555f1;p=html-minifier.git Push tag and attrs to stack --- diff --git a/src/htmlparser.js b/src/htmlparser.js index 26093cd..48aa66f 100644 --- a/src/htmlparser.js +++ b/src/htmlparser.js @@ -152,7 +152,8 @@ var HTMLParser = global.HTMLParser = function( html, handler ) { var index, chars, match, stack = [], last = html, prevTag, nextTag; stack.last = function() { - return this[ this.length - 1 ]; + var last = this[ this.length - 1 ]; + return last && last.tag; }; var startTag = startTagForHandler(handler); @@ -355,7 +356,7 @@ }); if ( !unary ) { - stack.push( tagName ); + stack.push( { tag: tagName, attrs: attrs } ); } else { unarySlash = tag.match( endingSlash ); @@ -378,7 +379,7 @@ // Find the closest opened tag of the same type var needle = tagName.toLowerCase(); for ( pos = stack.length - 1; pos >= 0; pos-- ) { - if ( stack[ pos ].toLowerCase() === needle ) { + if ( stack[ pos ].tag.toLowerCase() === needle ) { break; } } @@ -388,7 +389,7 @@ // Close all the open elements, up the stack for ( var i = stack.length - 1; i >= pos; i-- ) { if ( handler.end ) { - handler.end( stack[ i ] ); + handler.end( stack[ i ].tag ); } }