Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix existing and add new options #74

Merged
merged 6 commits into from
Feb 14, 2014
20 changes: 12 additions & 8 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ var voidElements = {
var re_nameEnd = /\s|\//;

function Parser(cbs, options){
this._options = options || {};
options = options || {};
this._options = options;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just move this to a single line & I'll merge.

this._cbs = cbs || {};

this._tagname = "";
Expand All @@ -89,6 +90,9 @@ function Parser(cbs, options){
this.startIndex = 0;
this.endIndex = null;

this._lowerCaseTagNames = "lowerCaseTags" in this._options ? !!this._options.lowerCaseTags : !this._options.xmlMode;
this._lowerCaseAttributeNames = "lowerCaseAttributeNames" in this._options ? !!this._options.lowerCaseAttributeNames : !this._options.xmlMode;

this._tokenizer = new Tokenizer(options, this);
}

Expand All @@ -111,7 +115,7 @@ Parser.prototype.ontext = function(data){
};

Parser.prototype.onopentagname = function(name){
if(!(this._options.xmlMode || "lowerCaseTags" in this._options) || this._options.lowerCaseTags){
if(this._lowerCaseTagNames){
name = name.toLowerCase();
}

Expand Down Expand Up @@ -151,7 +155,7 @@ Parser.prototype.onopentagend = function(){
Parser.prototype.onclosetag = function(name){
this._updatePosition(1);

if(!(this._options.xmlMode || "lowerCaseTags" in this._options) || this._options.lowerCaseTags){
if(this._lowerCaseTagNames){
name = name.toLowerCase();
}

Expand All @@ -174,7 +178,7 @@ Parser.prototype.onclosetag = function(name){
};

Parser.prototype.onselfclosingtag = function(){
if(this._options.xmlMode){
if(this._options.xmlMode || this._options.recognizeSelfClosing){
this._closeCurrentTag();
} else {
this.onopentagend();
Expand All @@ -197,7 +201,7 @@ Parser.prototype._closeCurrentTag = function(){
};

Parser.prototype.onattribname = function(name){
if(!(this._options.xmlMode || "lowerCaseAttributeNames" in this._options) || this._options.lowerCaseAttributeNames){
if(this._lowerCaseAttributeNames){
name = name.toLowerCase();
}
this._attribname = name;
Expand All @@ -224,7 +228,7 @@ Parser.prototype.ondeclaration = function(value){
var idx = value.search(re_nameEnd),
name = idx < 0 ? value : value.substr(0, idx);

if(!(this._options.xmlMode || "lowerCaseTags" in this._options) || this._options.lowerCaseTags){
if(this._lowerCaseTagNames){
name = name.toLowerCase();
}
this._cbs.onprocessinginstruction("!" + name, "!" + value);
Expand All @@ -236,7 +240,7 @@ Parser.prototype.onprocessinginstruction = function(value){
var idx = value.search(re_nameEnd),
name = idx < 0 ? value : value.substr(0, idx);

if(!(this._options.xmlMode || "lowerCaseTags" in this._options) || this._options.lowerCaseTags){
if(this._lowerCaseTagNames){
name = name.toLowerCase();
}
this._cbs.onprocessinginstruction("?" + name, "?" + value);
Expand All @@ -253,7 +257,7 @@ Parser.prototype.oncomment = function(value){
Parser.prototype.oncdata = function(value){
this._updatePosition(1);

if(this._options.xmlMode){
if(this._options.xmlMode || this._options.recognizeCDATA){
if(this._cbs.oncdatastart) this._cbs.oncdatastart();
if(this._cbs.ontext) this._cbs.ontext(value);
if(this._cbs.oncdataend) this._cbs.oncdataend();
Expand Down