html-parser
Advanced tools
Comparing version 0.1.0 to 0.2.0
{ | ||
"name": "html-parser", | ||
"version": "0.1.0", | ||
"description": "HTML/XML parser with less explosions", | ||
"author": { | ||
"name": "Tommy Montgomery", | ||
"email": "tmont@tmont.com", | ||
"url": "http://tmont.com/" | ||
}, | ||
"name": "html-parser", | ||
"version": "0.2.0", | ||
"description": "HTML/XML parser with less explosions", | ||
"keywords": [ "html", "xml", "parser", "explosion" ], | ||
"author": { | ||
"name": "Tommy Montgomery", | ||
"email": "tmont@tmont.com", | ||
"url": "http://tmont.com/" | ||
}, | ||
@@ -16,7 +17,10 @@ "main": "./src/parser.js", | ||
"repository": { "type": "git", "url": "git://github.com/tmont/html-parser.git" }, | ||
"devDependencies": { | ||
"mocha": ">= 1.1.0", | ||
"should": ">= 0.6.3" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/tmont/html-parser.git" | ||
}, | ||
"devDependencies": { | ||
"moczha": ">= 1.1.0", | ||
"should": ">= 0.6.3" | ||
}, | ||
@@ -23,0 +27,0 @@ "scripts": { |
@@ -11,3 +11,3 @@ var parseContext = require('./context'); | ||
var attributeValueRegex = !quote | ||
? /(.*?)[\s>]/ | ||
? /(.*?)(?=[\s>])/ | ||
: new RegExp(quote + '(.*?)' + quote); | ||
@@ -220,2 +220,3 @@ | ||
var sanitized = '', tagStack = []; | ||
var ignoring = false; | ||
var callbacks = { | ||
@@ -231,7 +232,10 @@ docType: function(value) { | ||
name = name.toLowerCase(); | ||
tagStack.push({ name: name }); | ||
if (toRemove.elements.indexOf(name) !== -1) { | ||
if (!ignoring) { | ||
ignoring = tagStack[tagStack.length - 1]; | ||
} | ||
return; | ||
} | ||
sanitized += '<' + name; | ||
tagStack.push(name); | ||
}, | ||
@@ -241,6 +245,2 @@ | ||
name = name.toLowerCase(); | ||
if (toRemove.elements.indexOf(name) !== -1) { | ||
return; | ||
} | ||
sanitized += token; | ||
if (token.length === 2) { | ||
@@ -250,2 +250,6 @@ //self closing | ||
} | ||
if (ignoring || toRemove.elements.indexOf(name) !== -1) { | ||
return; | ||
} | ||
sanitized += token; | ||
}, | ||
@@ -255,12 +259,19 @@ | ||
name = name.toLowerCase(); | ||
if (toRemove.elements.indexOf(name) !== -1) { | ||
if (tagStack.length && tagStack[tagStack.length - 1].name === name) { | ||
var scope = tagStack.pop(); | ||
if (scope === ignoring) { | ||
ignoring = null; | ||
} | ||
} | ||
if (ignoring || toRemove.elements.indexOf(name) !== -1) { | ||
return; | ||
} | ||
sanitized += '</' + name + '>'; | ||
if (tagStack.length && tagStack[tagStack.length - 1] === name) { | ||
tagStack.pop(); | ||
} | ||
}, | ||
attribute: function(name, value) { | ||
if (ignoring) { | ||
return; | ||
} | ||
name = name.toLowerCase(); | ||
@@ -275,2 +286,5 @@ if (toRemove.attributes.indexOf(name) !== -1) { | ||
text: function(value) { | ||
if (ignoring) { | ||
return; | ||
} | ||
sanitized += value; | ||
@@ -280,3 +294,3 @@ }, | ||
comment: function(value) { | ||
if (toRemove.comments) { | ||
if (ignoring || toRemove.comments) { | ||
return; | ||
@@ -288,8 +302,14 @@ } | ||
cdata: function(value) { | ||
if (tagStack.indexOf('script') !== -1 || tagStack.indexOf('xmp') !== -1) { | ||
sanitized += value; | ||
if (ignoring) { | ||
return; | ||
} | ||
else { | ||
sanitized += '<![CDATA[' + value + ']]>'; | ||
for (var i = tagStack.length - 1; i >= 0; i--) { | ||
if (tagStack[i].name === 'script' || tagStack[i].name === 'xmp') { | ||
sanitized += value; | ||
return; | ||
} | ||
} | ||
sanitized += '<![CDATA[' + value + ']]>'; | ||
} | ||
@@ -296,0 +316,0 @@ }; |
@@ -37,3 +37,4 @@ var should = require('should'); | ||
it('should remove specified elements', function() { | ||
var sanitized = helpers.parser.sanitize('<foo><bar><baz><bat></bat></baz></bar><bat></bat></foo>', { | ||
var html = '<foo><bar><baz><bat foo=bar>asdf</bat></baz></bar><bat><!-- comment --></bat></foo>'; | ||
var sanitized = helpers.parser.sanitize(html, { | ||
elements: [ 'bat' ] | ||
@@ -40,0 +41,0 @@ }); |
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
59791
32
1110
0
61