From 355ec734d3aa39e4281d02a9a7b2bb1e1a5555f1 Mon Sep 17 00:00:00 2001 From: Duncan Beevers Date: Mon, 1 Sep 2014 23:26:39 -0500 Subject: [PATCH] Push tag and attrs to stack --- src/htmlparser.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 ); } } -- 2.34.1