context-parser
Advanced tools
Comparing version 1.1.1 to 1.1.2
{ | ||
"name": "context-parser", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"homepage": "https://github.com/yahoo/context-parser", | ||
@@ -5,0 +5,0 @@ "description": "HTML5 Context Parser", |
{ | ||
"name": "context-parser", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"licenses": [ | ||
@@ -5,0 +5,0 @@ { |
@@ -335,2 +335,3 @@ /* | ||
* @function FastParser#getStartTagName | ||
* @depreciated Replace it by getCurrentTagIndex and getCurrentTag | ||
* | ||
@@ -341,6 +342,28 @@ * @returns {string} The current handling start tag name | ||
FastParser.prototype.getStartTagName = function() { | ||
return this.tags[0].toLowerCase(); | ||
return this.tags[0] !== undefined? this.tags[0].toLowerCase() : undefined; | ||
}; | ||
/** | ||
* @function FastParser#getCurrentTagIndex | ||
* | ||
* @returns {integer} The current handling tag Idx | ||
* | ||
*/ | ||
FastParser.prototype.getCurrentTagIndex = function() { | ||
return this.tagIdx; | ||
}; | ||
/** | ||
* @function FastParser#getCurrentTag | ||
* | ||
* @params {integer} The tag Idx | ||
* | ||
* @returns {string} The current tag name indexed by tag Idx | ||
* | ||
*/ | ||
FastParser.prototype.getCurrentTag = function(tagIdx) { | ||
return tagIdx === 0 || tagIdx === 1? (this.tags[tagIdx] !== undefined? this.tags[tagIdx].toLowerCase():undefined) : undefined; | ||
}; | ||
/** | ||
* @function FastParser#getAttributeName | ||
@@ -347,0 +370,0 @@ * |
@@ -219,2 +219,22 @@ /* | ||
describe('#getCurrentTagIndex and #getCurrentTag', function(){ | ||
it('should return correct tag name/index', function(){ | ||
[ { html: "<div class='classname' style='color:red'></div>", tag0: 'div', tag1: 'div', index: 1}, | ||
{ html: "<div class='classname' style='color:red'></div> ", tag0: 'div', tag1: 'div', index: 1}, | ||
{ html: "<div class='classname' style='color:red'></div><img>", tag0: 'img', tag1: 'div', index: 0}, | ||
{ html: "<div class='classname' style='color:red'></div><img ", tag0: 'img', tag1: 'div', index: 0}, | ||
{ html: "<div class='classname' style='color:red'></div><img></im", tag0: 'img', tag1: 'im', index: 1}, | ||
{ html: "<div class='classname' style='color:red'></div><img></img ",tag0: 'img', tag1: 'img', index: 1}, | ||
].forEach(function(testObj) { | ||
var p1 = new Parser(config); | ||
p1.contextualize(testObj.html); | ||
assert.equal(p1.getCurrentTag(0), testObj.tag0); | ||
assert.equal(p1.getCurrentTag(1), testObj.tag1); | ||
assert.equal(p1.getCurrentTagIndex(), testObj.index); | ||
}); | ||
}); | ||
}); | ||
describe('#Constructor', function(){ | ||
@@ -221,0 +241,0 @@ |
1158660
2765