Skip to content

Commit

Permalink
[parser] properly removed self-closing tag support
Browse files Browse the repository at this point in the history
also replaced call to `Array#slice` with setting the stack's `length`
property
  • Loading branch information
fb55 committed Aug 22, 2013
1 parent e4fb613 commit 80a1ecb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/Parser.js
Expand Up @@ -154,32 +154,41 @@ Parser.prototype.onclosetag = function(name){
if(!(this._options.xmlMode || "lowerCaseTags" in this._options) || this._options.lowerCaseTags){
name = name.toLowerCase();
}

if(this._stack.length && (!(name in voidElements) || this._options.xmlMode)){
var pos = this._stack.lastIndexOf(name);
if(pos !== -1){
if(this._cbs.onclosetag){
pos = this._stack.length - pos;
while(pos--) this._cbs.onclosetag(this._stack.pop());
}
else this._stack.splice(pos);
else this._stack.length = pos;
} else if(name === "p" && !this._options.xmlMode){
this.onopentagname(name);
this.onselfclosingtag();
this._closeCurrentTag();
}
} else if(!this._options.xmlMode && (name === "br" || name === "p")){
this.onopentagname(name);
this.onselfclosingtag();
this._closeCurrentTag();
}
};

Parser.prototype.onselfclosingtag = function(){
if(this._options.xmlMode){
this._closeCurrentTag();
} else {
this.onopentagend();
}
};

Parser.prototype._closeCurrentTag = function(){
var name = this._tagname;

this.onopentagend();

//self-closing tags will be on the top of the stack
//(cheaper check than in onclosetag)
if(!this._options.xmlMode && this._stack[this._stack.length-1] === name){
if(this._stack[this._stack.length-1] === name){
if(this._cbs.onclosetag){
this._cbs.onclosetag(name);
}
Expand Down

0 comments on commit 80a1ecb

Please sign in to comment.