aboutsummaryrefslogtreecommitdiff
path: root/node_modules/domhandler
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/domhandler')
-rw-r--r--node_modules/domhandler/.travis.yml6
-rw-r--r--node_modules/domhandler/LICENSE11
-rw-r--r--node_modules/domhandler/index.js174
-rw-r--r--node_modules/domhandler/package.json28
-rw-r--r--node_modules/domhandler/readme.md99
-rw-r--r--node_modules/domhandler/test/cases/01-basic.json41
-rw-r--r--node_modules/domhandler/test/cases/02-single_tag_1.json21
-rw-r--r--node_modules/domhandler/test/cases/03-single_tag_2.json21
-rw-r--r--node_modules/domhandler/test/cases/04-unescaped_in_script.json27
-rw-r--r--node_modules/domhandler/test/cases/05-tags_in_comment.json18
-rw-r--r--node_modules/domhandler/test/cases/06-comment_in_script.json18
-rw-r--r--node_modules/domhandler/test/cases/07-unescaped_in_style.json20
-rw-r--r--node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json20
-rw-r--r--node_modules/domhandler/test/cases/09-unquoted_attrib.json20
-rw-r--r--node_modules/domhandler/test/cases/10-singular_attribute.json15
-rw-r--r--node_modules/domhandler/test/cases/11-text_outside_tags.json20
-rw-r--r--node_modules/domhandler/test/cases/12-text_only.json11
-rw-r--r--node_modules/domhandler/test/cases/13-comment_in_text.json19
-rw-r--r--node_modules/domhandler/test/cases/14-comment_in_text_in_script.json18
-rw-r--r--node_modules/domhandler/test/cases/15-non-verbose.json22
-rw-r--r--node_modules/domhandler/test/cases/16-normalize_whitespace.json47
-rw-r--r--node_modules/domhandler/test/cases/17-xml_namespace.json18
-rw-r--r--node_modules/domhandler/test/cases/18-enforce_empty_tags.json16
-rw-r--r--node_modules/domhandler/test/cases/19-ignore_empty_tags.json20
-rw-r--r--node_modules/domhandler/test/cases/20-template_script_tags.json20
-rw-r--r--node_modules/domhandler/test/cases/21-conditional_comments.json15
-rw-r--r--node_modules/domhandler/test/cases/22-lowercase_tags.json41
-rw-r--r--node_modules/domhandler/test/tests.js59
28 files changed, 865 insertions, 0 deletions
diff --git a/node_modules/domhandler/.travis.yml b/node_modules/domhandler/.travis.yml
new file mode 100644
index 000000000..8d7f0cd71
--- /dev/null
+++ b/node_modules/domhandler/.travis.yml
@@ -0,0 +1,6 @@
+language: node_js
+node_js:
+ - 0.4
+ - 0.6
+ - 0.8
+ - 0.9
diff --git a/node_modules/domhandler/LICENSE b/node_modules/domhandler/LICENSE
new file mode 100644
index 000000000..c464f863e
--- /dev/null
+++ b/node_modules/domhandler/LICENSE
@@ -0,0 +1,11 @@
+Copyright (c) Felix Böhm
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS,
+EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/node_modules/domhandler/index.js b/node_modules/domhandler/index.js
new file mode 100644
index 000000000..68816a0d0
--- /dev/null
+++ b/node_modules/domhandler/index.js
@@ -0,0 +1,174 @@
+var ElementType = require("domelementtype");
+
+var re_whitespace = /\s+/g;
+
+function DomHandler(callback, options, elementCB){
+ if(typeof callback === "object"){
+ elementCB = options;
+ options = callback;
+ callback = null;
+ } else if(typeof options === "function"){
+ elementCB = options;
+ options = defaultOpts;
+ }
+ this._callback = callback;
+ this._options = options || defaultOpts;
+ this._elementCB = elementCB;
+ this.dom = [];
+ this._done = false;
+ this._tagStack = [];
+}
+
+//default options
+var defaultOpts = {
+ normalizeWhitespace: false //Replace all whitespace with single spaces
+};
+
+//Resets the handler back to starting state
+DomHandler.prototype.onreset = function(){
+ DomHandler.call(this, this._callback, this._options, this._elementCB);
+};
+
+//Signals the handler that parsing is done
+DomHandler.prototype.onend = function(){
+ if(this._done) return;
+ this._done = true;
+ this._handleCallback(null);
+};
+
+DomHandler.prototype._handleCallback =
+DomHandler.prototype.onerror = function(error){
+ if(typeof this._callback === "function"){
+ this._callback(error, this.dom);
+ } else {
+ if(error) throw error;
+ }
+};
+
+DomHandler.prototype.onclosetag = function(name){
+ //if(this._tagStack.pop().name !== name) this._handleCallback(Error("Tagname didn't match!"));
+ var elem = this._tagStack.pop();
+ if(this._elementCB) this._elementCB(elem);
+};
+
+DomHandler.prototype._addDomElement = function(element){
+ var lastTag = this._tagStack[this._tagStack.length - 1];
+
+ if(lastTag){
+ lastTag.children.push(element);
+ } else { //There aren't parent elements
+ this.dom.push(element);
+ }
+};
+
+DomHandler.prototype.onopentag = function(name, attribs){
+ var lastTag = this._tagStack[this._tagStack.length - 1];
+
+ var element = {
+ type: name === "script" ? ElementType.Script : name === "style" ? ElementType.Style : ElementType.Tag,
+ name: name,
+ attribs: attribs,
+ children: [],
+ prev: null,
+ next: null,
+ parent: lastTag || null
+ };
+
+ if(lastTag){
+ var idx = lastTag.children.length;
+ while(idx > 0){
+ if(ElementType.isTag(lastTag.children[--idx])){
+ element.prev = lastTag.children[idx];
+ lastTag.children[idx].next = element;
+ break;
+ }
+ }
+ lastTag.children.push(element);
+ } else {
+ this.dom.push(element);
+ }
+
+ this._tagStack.push(element);
+};
+
+DomHandler.prototype.ontext = function(data){
+ //the ignoreWhitespace is officially dropped, but for now,
+ //it's an alias for normalizeWhitespace
+ var normalize = this._options.normalizeWhitespace || this._options.ignoreWhitespace;
+
+ var lastTag;
+
+ if(!this._tagStack.length && this.dom.length && (lastTag = this.dom[this.dom.length-1]).type === ElementType.Text){
+ if(normalize){
+ lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
+ } else {
+ lastTag.data += data;
+ }
+ } else {
+ if(
+ this._tagStack.length &&
+ (lastTag = this._tagStack[this._tagStack.length - 1]) &&
+ (lastTag = lastTag.children[lastTag.children.length - 1]) &&
+ lastTag.type === ElementType.Text
+ ){
+ if(normalize){
+ lastTag.data = (lastTag.data + data).replace(re_whitespace, " ");
+ } else {
+ lastTag.data += data;
+ }
+ } else {
+ if(normalize){
+ data = data.replace(re_whitespace, " ");
+ }
+
+ this._addDomElement({
+ data: data,
+ type: ElementType.Text
+ });
+ }
+ }
+};
+
+DomHandler.prototype.oncomment = function(data){
+ var lastTag = this._tagStack[this._tagStack.length - 1];
+
+ if(lastTag && lastTag.type === ElementType.Comment){
+ lastTag.data += data;
+ return;
+ }
+
+ var element = {
+ data: data,
+ type: ElementType.Comment
+ };
+
+ this._addDomElement(element);
+ this._tagStack.push(element);
+};
+
+DomHandler.prototype.oncdatastart = function(){
+ var element = {
+ children: [{
+ data: "",
+ type: ElementType.Text
+ }],
+ type: ElementType.CDATA
+ };
+
+ this._addDomElement(element);
+ this._tagStack.push(element);
+};
+
+DomHandler.prototype.oncommentend = DomHandler.prototype.oncdataend = function(){
+ this._tagStack.pop();
+};
+
+DomHandler.prototype.onprocessinginstruction = function(name, data){
+ this._addDomElement({
+ name: name,
+ data: data,
+ type: ElementType.Directive
+ });
+};
+
+module.exports = DomHandler; \ No newline at end of file
diff --git a/node_modules/domhandler/package.json b/node_modules/domhandler/package.json
new file mode 100644
index 000000000..4052150e6
--- /dev/null
+++ b/node_modules/domhandler/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "domhandler",
+ "version": "2.1.0",
+ "description": "handler for htmlparser2 that turns pages into a dom",
+ "main": "index.js",
+ "directories": {
+ "test": "tests"
+ },
+ "scripts": {
+ "test": "mocha -R list"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git://github.com/fb55/domhandler.git"
+ },
+ "keywords": [
+ "dom",
+ "htmlparser2"
+ ],
+ "dependencies": {
+ "domelementtype": "1"
+ },
+ "devDependencies": {
+ "htmlparser2": "2.3",
+ "mocha": "1"
+ },
+ "author": "Felix Boehm <me@feedic.com>"
+}
diff --git a/node_modules/domhandler/readme.md b/node_modules/domhandler/readme.md
new file mode 100644
index 000000000..a9214a3dd
--- /dev/null
+++ b/node_modules/domhandler/readme.md
@@ -0,0 +1,99 @@
+#DOMHandler [![Build Status](https://secure.travis-ci.org/fb55/DomHandler.png)](http://travis-ci.org/fb55/DomHandler)
+
+The DOM handler (formally known as DefaultHandler) creates a tree containing all nodes of a page. The tree may be manipulated using the DOMUtils library.
+
+##Usage
+```javascript
+var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
+// var parser = new Parser(handler[, options]);
+```
+
+##Example
+```javascript
+var htmlparser = require("htmlparser2");
+var rawHtml = "Xyz <script language= javascript>var foo = '<<bar>>';< / script><!--<!-- Waah! -- -->";
+var handler = new htmlparser.DomHandler(function (error, dom) {
+ if (error)
+ [...do something for errors...]
+ else
+ [...parsing done, do something...]
+ console.log(dom);
+});
+var parser = new htmlparser.Parser(handler);
+parser.write(rawHtml);
+parser.done();
+```
+
+Output:
+
+```javascript
+[{
+ data: 'Xyz ',
+ type: 'text'
+}, {
+ type: 'script',
+ name: 'script',
+ attribs: {
+ language: 'javascript'
+ },
+ children: [{
+ data: 'var foo = \'<bar>\';<',
+ type: 'text'
+ }]
+}, {
+ data: '<!-- Waah! -- ',
+ type: 'comment'
+}]
+```
+
+##Option: ignoreWhitespace
+Indicates whether the DOM should exclude text nodes that consists solely of whitespace. The default value is "false".
+
+The following HTML will be used:
+
+```html
+<font>
+ <br>this is the text
+<font>
+```
+
+###Example: true
+
+```javascript
+[{
+ type: 'tag',
+ name: 'font',
+ children: [{
+ type: 'tag',
+ name: 'br'
+ }, {
+ data: 'this is the text\n',
+ type: 'text'
+ }, {
+ type: 'tag',
+ name: 'font'
+ }]
+}]
+```
+
+###Example: false
+
+```javascript
+[{
+ type: 'tag',
+ name: 'font',
+ children: [{
+ data: '\n\t',
+ type: 'text'
+ }, {
+ type: 'tag',
+ name: 'br'
+ }, {
+ data: 'this is the text\n',
+ type: 'text'
+ }, {
+ type: 'tag',
+ name: 'font'
+ }]
+}]
+``` \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/01-basic.json b/node_modules/domhandler/test/cases/01-basic.json
new file mode 100644
index 000000000..e7952ec9e
--- /dev/null
+++ b/node_modules/domhandler/test/cases/01-basic.json
@@ -0,0 +1,41 @@
+{
+ "name": "Basic test",
+ "options": {},
+ "html": "<!DOCTYPE html><html><title>The Title</title><body>Hello world</body></html>",
+ "expected": [
+ {
+ "name": "!doctype",
+ "data": "!DOCTYPE html",
+ "type": "directive"
+ },
+ {
+ "type": "tag",
+ "name": "html",
+ "attribs": {},
+ "children": [
+ {
+ "type": "tag",
+ "name": "title",
+ "attribs": {},
+ "children": [
+ {
+ "data": "The Title",
+ "type": "text"
+ }
+ ]
+ },
+ {
+ "type": "tag",
+ "name": "body",
+ "attribs": {},
+ "children": [
+ {
+ "data": "Hello world",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/02-single_tag_1.json b/node_modules/domhandler/test/cases/02-single_tag_1.json
new file mode 100644
index 000000000..51ff84577
--- /dev/null
+++ b/node_modules/domhandler/test/cases/02-single_tag_1.json
@@ -0,0 +1,21 @@
+{
+ "name": "Single Tag 1",
+ "options": {},
+ "html": "<br>text</br>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": "text",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/03-single_tag_2.json b/node_modules/domhandler/test/cases/03-single_tag_2.json
new file mode 100644
index 000000000..1c56dc9d9
--- /dev/null
+++ b/node_modules/domhandler/test/cases/03-single_tag_2.json
@@ -0,0 +1,21 @@
+{
+ "name": "Single Tag 2",
+ "options": {},
+ "html": "<br>text<br>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": "text",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/04-unescaped_in_script.json b/node_modules/domhandler/test/cases/04-unescaped_in_script.json
new file mode 100644
index 000000000..f31f5fad6
--- /dev/null
+++ b/node_modules/domhandler/test/cases/04-unescaped_in_script.json
@@ -0,0 +1,27 @@
+{
+ "name": "Unescaped chars in script",
+ "options": {},
+ "html": "<head><script language=\"Javascript\">var foo = \"<bar>\"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";</script></head>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "head",
+ "attribs": {},
+ "children": [
+ {
+ "type": "script",
+ "name": "script",
+ "attribs": {
+ "language": "Javascript"
+ },
+ "children": [
+ {
+ "data": "var foo = \"<bar>\"; alert(2 > foo); var baz = 10 << 2; var zip = 10 >> 1; var yap = \"<<>>>><<\";",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/05-tags_in_comment.json b/node_modules/domhandler/test/cases/05-tags_in_comment.json
new file mode 100644
index 000000000..2d22d9e1d
--- /dev/null
+++ b/node_modules/domhandler/test/cases/05-tags_in_comment.json
@@ -0,0 +1,18 @@
+{
+ "name": "Special char in comment",
+ "options": {},
+ "html": "<head><!-- commented out tags <title>Test</title>--></head>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "head",
+ "attribs": {},
+ "children": [
+ {
+ "data": " commented out tags <title>Test</title>",
+ "type": "comment"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/06-comment_in_script.json b/node_modules/domhandler/test/cases/06-comment_in_script.json
new file mode 100644
index 000000000..9a21cdabf
--- /dev/null
+++ b/node_modules/domhandler/test/cases/06-comment_in_script.json
@@ -0,0 +1,18 @@
+{
+ "name": "Script source in comment",
+ "options": {},
+ "html": "<script><!--var foo = 1;--></script>",
+ "expected": [
+ {
+ "type": "script",
+ "name": "script",
+ "attribs": {},
+ "children": [
+ {
+ "data": "<!--var foo = 1;-->",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/07-unescaped_in_style.json b/node_modules/domhandler/test/cases/07-unescaped_in_style.json
new file mode 100644
index 000000000..77438fdc1
--- /dev/null
+++ b/node_modules/domhandler/test/cases/07-unescaped_in_style.json
@@ -0,0 +1,20 @@
+{
+ "name": "Unescaped chars in style",
+ "options": {},
+ "html": "<style type=\"text/css\">\n body > p\n\t{ font-weight: bold; }</style>",
+ "expected": [
+ {
+ "type": "style",
+ "name": "style",
+ "attribs": {
+ "type": "text/css"
+ },
+ "children": [
+ {
+ "data": "\n body > p\n\t{ font-weight: bold; }",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json b/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json
new file mode 100644
index 000000000..5c2492e22
--- /dev/null
+++ b/node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json
@@ -0,0 +1,20 @@
+{
+ "name": "Extra spaces in tag",
+ "options": {},
+ "html": "<font\t\n size='14' \n>the text</\t\nfont\t \n>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "font",
+ "attribs": {
+ "size": "14"
+ },
+ "children": [
+ {
+ "data": "the text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/09-unquoted_attrib.json b/node_modules/domhandler/test/cases/09-unquoted_attrib.json
new file mode 100644
index 000000000..543cceeed
--- /dev/null
+++ b/node_modules/domhandler/test/cases/09-unquoted_attrib.json
@@ -0,0 +1,20 @@
+{
+ "name": "Unquoted attributes",
+ "options": {},
+ "html": "<font size= 14>the text</font>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "font",
+ "attribs": {
+ "size": "14"
+ },
+ "children": [
+ {
+ "data": "the text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/10-singular_attribute.json b/node_modules/domhandler/test/cases/10-singular_attribute.json
new file mode 100644
index 000000000..544636e49
--- /dev/null
+++ b/node_modules/domhandler/test/cases/10-singular_attribute.json
@@ -0,0 +1,15 @@
+{
+ "name": "Singular attribute",
+ "options": {},
+ "html": "<option value='foo' selected>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "option",
+ "attribs": {
+ "value": "foo",
+ "selected": ""
+ }
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/11-text_outside_tags.json b/node_modules/domhandler/test/cases/11-text_outside_tags.json
new file mode 100644
index 000000000..07a0d296e
--- /dev/null
+++ b/node_modules/domhandler/test/cases/11-text_outside_tags.json
@@ -0,0 +1,20 @@
+{
+ "name": "Text outside tags",
+ "options": {},
+ "html": "Line one\n<br>\nline two",
+ "expected": [
+ {
+ "data": "Line one\n",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": "\nline two",
+ "type": "text"
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/12-text_only.json b/node_modules/domhandler/test/cases/12-text_only.json
new file mode 100644
index 000000000..342dc45f0
--- /dev/null
+++ b/node_modules/domhandler/test/cases/12-text_only.json
@@ -0,0 +1,11 @@
+{
+ "name": "Only text",
+ "options": {},
+ "html": "this is the text",
+ "expected": [
+ {
+ "data": "this is the text",
+ "type": "text"
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/13-comment_in_text.json b/node_modules/domhandler/test/cases/13-comment_in_text.json
new file mode 100644
index 000000000..672dbbea2
--- /dev/null
+++ b/node_modules/domhandler/test/cases/13-comment_in_text.json
@@ -0,0 +1,19 @@
+{
+ "name": "Comment within text",
+ "options": {},
+ "html": "this is <!-- the comment --> the text",
+ "expected": [
+ {
+ "data": "this is ",
+ "type": "text"
+ },
+ {
+ "data": " the comment ",
+ "type": "comment"
+ },
+ {
+ "data": " the text",
+ "type": "text"
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json b/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json
new file mode 100644
index 000000000..b69d04bd1
--- /dev/null
+++ b/node_modules/domhandler/test/cases/14-comment_in_text_in_script.json
@@ -0,0 +1,18 @@
+{
+ "name": "Comment within text within script",
+ "options": {},
+ "html": "<script>this is <!-- the comment --> the text</script>",
+ "expected": [
+ {
+ "type": "script",
+ "name": "script",
+ "attribs": {},
+ "children": [
+ {
+ "data": "this is <!-- the comment --> the text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/15-non-verbose.json b/node_modules/domhandler/test/cases/15-non-verbose.json
new file mode 100644
index 000000000..069db840a
--- /dev/null
+++ b/node_modules/domhandler/test/cases/15-non-verbose.json
@@ -0,0 +1,22 @@
+{
+ "name": "Option 'verbose' set to 'false'",
+ "options": {
+ "verbose": false
+ },
+ "html": "<font\t\n size='14' \n>the text</\t\nfont\t \n>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "font",
+ "attribs": {
+ "size": "14"
+ },
+ "children": [
+ {
+ "data": "the text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/16-normalize_whitespace.json b/node_modules/domhandler/test/cases/16-normalize_whitespace.json
new file mode 100644
index 000000000..d4490af48
--- /dev/null
+++ b/node_modules/domhandler/test/cases/16-normalize_whitespace.json
@@ -0,0 +1,47 @@
+{
+ "name": "Normalize whitespace",
+ "options": {
+ "normalizeWhitespace": true
+ },
+ "html": "Line one\n<br>\t \r\n\f <br>\nline two<font><br> x </font>",
+ "expected": [
+ {
+ "data": "Line one ",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": " ",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": " line two",
+ "type": "text"
+ },
+ {
+ "type": "tag",
+ "name": "font",
+ "attribs": {},
+ "children": [
+ {
+ "type": "tag",
+ "name": "br",
+ "attribs": {}
+ },
+ {
+ "data": " x ",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/17-xml_namespace.json b/node_modules/domhandler/test/cases/17-xml_namespace.json
new file mode 100644
index 000000000..2171c49ed
--- /dev/null
+++ b/node_modules/domhandler/test/cases/17-xml_namespace.json
@@ -0,0 +1,18 @@
+{
+ "name": "XML Namespace",
+ "options": {},
+ "html": "<ns:tag>text</ns:tag>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "ns:tag",
+ "attribs": {},
+ "children": [
+ {
+ "data": "text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/18-enforce_empty_tags.json b/node_modules/domhandler/test/cases/18-enforce_empty_tags.json
new file mode 100644
index 000000000..ce6c45554
--- /dev/null
+++ b/node_modules/domhandler/test/cases/18-enforce_empty_tags.json
@@ -0,0 +1,16 @@
+{
+ "name": "Enforce empty tags",
+ "options": {},
+ "html": "<link>text</link>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "link",
+ "attribs": {}
+ },
+ {
+ "data": "text",
+ "type": "text"
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/19-ignore_empty_tags.json b/node_modules/domhandler/test/cases/19-ignore_empty_tags.json
new file mode 100644
index 000000000..fe59cf913
--- /dev/null
+++ b/node_modules/domhandler/test/cases/19-ignore_empty_tags.json
@@ -0,0 +1,20 @@
+{
+ "name": "Ignore empty tags (xml mode)",
+ "options": {
+ "xmlMode": true
+ },
+ "html": "<link>text</link>",
+ "expected": [
+ {
+ "type": "tag",
+ "name": "link",
+ "attribs": {},
+ "children": [
+ {
+ "data": "text",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/20-template_script_tags.json b/node_modules/domhandler/test/cases/20-template_script_tags.json
new file mode 100644
index 000000000..dae5f1f93
--- /dev/null
+++ b/node_modules/domhandler/test/cases/20-template_script_tags.json
@@ -0,0 +1,20 @@
+{
+ "name": "Template script tags",
+ "options": {},
+ "html": "<script type=\"text/template\"><h1>Heading1</h1></script>",
+ "expected": [
+ {
+ "type": "script",
+ "name": "script",
+ "attribs": {
+ "type": "text/template"
+ },
+ "children": [
+ {
+ "data": "<h1>Heading1</h1>",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/21-conditional_comments.json b/node_modules/domhandler/test/cases/21-conditional_comments.json
new file mode 100644
index 000000000..c034acd1a
--- /dev/null
+++ b/node_modules/domhandler/test/cases/21-conditional_comments.json
@@ -0,0 +1,15 @@
+{
+ "name": "Conditional comments",
+ "options": {},
+ "html": "<!--[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]--><!--[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]-->",
+ "expected": [
+ {
+ "data": "[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]",
+ "type": "comment"
+ },
+ {
+ "data": "[if lt IE 7]> <html class='no-js ie6 oldie' lang='en'> <![endif]",
+ "type": "comment"
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/cases/22-lowercase_tags.json b/node_modules/domhandler/test/cases/22-lowercase_tags.json
new file mode 100644
index 000000000..b3d70e432
--- /dev/null
+++ b/node_modules/domhandler/test/cases/22-lowercase_tags.json
@@ -0,0 +1,41 @@
+{
+ "name": "lowercase tags",
+ "options": {},
+ "html": "<!DOCTYPE html><HTML><TITLE>The Title</title><BODY>Hello world</body></html>",
+ "expected": [
+ {
+ "name": "!doctype",
+ "data": "!DOCTYPE html",
+ "type": "directive"
+ },
+ {
+ "type": "tag",
+ "name": "html",
+ "attribs": {},
+ "children": [
+ {
+ "type": "tag",
+ "name": "title",
+ "attribs": {},
+ "children": [
+ {
+ "data": "The Title",
+ "type": "text"
+ }
+ ]
+ },
+ {
+ "type": "tag",
+ "name": "body",
+ "attribs": {},
+ "children": [
+ {
+ "data": "Hello world",
+ "type": "text"
+ }
+ ]
+ }
+ ]
+ }
+ ]
+} \ No newline at end of file
diff --git a/node_modules/domhandler/test/tests.js b/node_modules/domhandler/test/tests.js
new file mode 100644
index 000000000..fc9d2cc87
--- /dev/null
+++ b/node_modules/domhandler/test/tests.js
@@ -0,0 +1,59 @@
+var fs = require("fs"),
+ path = require("path"),
+ assert = require("assert"),
+ util = require("util"),
+ ElementType = require("domelementtype"),
+ Parser = require("htmlparser2").Parser,
+ Handler = require("../");
+
+var basePath = path.resolve(__dirname, "cases"),
+ inspectOpts = { showHidden: true, depth: null };
+
+fs
+.readdirSync(basePath)
+.filter(RegExp.prototype.test, /\.json$/) //only allow .json files
+.map(function(name){
+ return path.resolve(basePath, name);
+})
+.map(require)
+.forEach(function(test){
+ it(test.name, function(){
+ var expected = test.expected;
+
+ var handler = new Handler(function(err, actual){
+ assert.ifError(err);
+ try {
+ compare(expected, actual);
+ } catch(e){
+ e.expected = util.inspect(expected, inspectOpts);
+ e.actual = util.inspect(actual, inspectOpts);
+ throw e;
+ }
+ }, test.options);
+
+ var data = test.html;
+
+ var parser = new Parser(handler, test.options);
+
+ //first, try to run the test via chunks
+ for(var i = 0; i < data.length; i++){
+ parser.write(data.charAt(i));
+ }
+ parser.done();
+
+ //then parse everything
+ parser.parseComplete(data);
+ });
+});
+
+function compare(expected, result){
+ assert.equal(typeof expected, typeof result, "types didn't match");
+ if(typeof expected !== "object" || expected === null){
+ assert.strictEqual(expected, result, "result doesn't equal expected");
+ } else {
+ for(var prop in expected){
+ assert.ok(prop in result, "result didn't contain property " + prop);
+ compare(expected[prop], result[prop]);
+ }
+ }
+} \ No newline at end of file