Skip to content

Commit

Permalink
Merge pull request #74 from patrick-steele-idem/master
Browse files Browse the repository at this point in the history
Fix existing and add new options
  • Loading branch information
fb55 committed Feb 14, 2014
2 parents 475a830 + 0fc5419 commit 55ce8d2
Showing 1 changed file with 17 additions and 25 deletions.
42 changes: 17 additions & 25 deletions lib/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,16 @@ function Parser(cbs, options) {
this.startIndex = 0;
this.endIndex = null;

this._tokenizer = new Tokenizer(options, this);
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(this._options, this);
}

require("util").inherits(Parser, require("events").EventEmitter);
Expand All @@ -122,10 +131,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 @@ -171,10 +177,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 @@ -199,7 +202,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 @@ -222,12 +225,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 Down Expand Up @@ -255,10 +253,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 @@ -270,10 +265,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 @@ -290,7 +282,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

0 comments on commit 55ce8d2

Please sign in to comment.