Push tag and attrs to stack
authorDuncan Beevers <duncan@dweebd.com>
Tue, 2 Sep 2014 04:26:39 +0000 (23:26 -0500)
committerDuncan Beevers <duncan@dweebd.com>
Tue, 2 Sep 2014 11:32:37 +0000 (06:32 -0500)
src/htmlparser.js

index 26093cd..48aa66f 100644 (file)
   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);
       });
 
       if ( !unary ) {
-        stack.push( tagName );
+        stack.push( { tag: tagName, attrs: attrs } );
       }
       else {
         unarySlash = tag.match( endingSlash );
         // 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;
           }
         }
         // 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 );
           }
         }