From de98e0b232509d5f40c135d540a70e415272ff85 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Wed, 3 May 2017 15:35:00 +0200 Subject: node_modules --- node_modules/domhandler/.travis.yml | 6 + node_modules/domhandler/LICENSE | 11 ++ node_modules/domhandler/index.js | 174 +++++++++++++++++++++ node_modules/domhandler/package.json | 28 ++++ node_modules/domhandler/readme.md | 99 ++++++++++++ node_modules/domhandler/test/cases/01-basic.json | 41 +++++ .../domhandler/test/cases/02-single_tag_1.json | 21 +++ .../domhandler/test/cases/03-single_tag_2.json | 21 +++ .../test/cases/04-unescaped_in_script.json | 27 ++++ .../domhandler/test/cases/05-tags_in_comment.json | 18 +++ .../test/cases/06-comment_in_script.json | 18 +++ .../test/cases/07-unescaped_in_style.json | 20 +++ .../test/cases/08-extra_spaces_in_tag.json | 20 +++ .../domhandler/test/cases/09-unquoted_attrib.json | 20 +++ .../test/cases/10-singular_attribute.json | 15 ++ .../test/cases/11-text_outside_tags.json | 20 +++ .../domhandler/test/cases/12-text_only.json | 11 ++ .../domhandler/test/cases/13-comment_in_text.json | 19 +++ .../test/cases/14-comment_in_text_in_script.json | 18 +++ .../domhandler/test/cases/15-non-verbose.json | 22 +++ .../test/cases/16-normalize_whitespace.json | 47 ++++++ .../domhandler/test/cases/17-xml_namespace.json | 18 +++ .../test/cases/18-enforce_empty_tags.json | 16 ++ .../test/cases/19-ignore_empty_tags.json | 20 +++ .../test/cases/20-template_script_tags.json | 20 +++ .../test/cases/21-conditional_comments.json | 15 ++ .../domhandler/test/cases/22-lowercase_tags.json | 41 +++++ node_modules/domhandler/test/tests.js | 59 +++++++ 28 files changed, 865 insertions(+) create mode 100644 node_modules/domhandler/.travis.yml create mode 100644 node_modules/domhandler/LICENSE create mode 100644 node_modules/domhandler/index.js create mode 100644 node_modules/domhandler/package.json create mode 100644 node_modules/domhandler/readme.md create mode 100644 node_modules/domhandler/test/cases/01-basic.json create mode 100644 node_modules/domhandler/test/cases/02-single_tag_1.json create mode 100644 node_modules/domhandler/test/cases/03-single_tag_2.json create mode 100644 node_modules/domhandler/test/cases/04-unescaped_in_script.json create mode 100644 node_modules/domhandler/test/cases/05-tags_in_comment.json create mode 100644 node_modules/domhandler/test/cases/06-comment_in_script.json create mode 100644 node_modules/domhandler/test/cases/07-unescaped_in_style.json create mode 100644 node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json create mode 100644 node_modules/domhandler/test/cases/09-unquoted_attrib.json create mode 100644 node_modules/domhandler/test/cases/10-singular_attribute.json create mode 100644 node_modules/domhandler/test/cases/11-text_outside_tags.json create mode 100644 node_modules/domhandler/test/cases/12-text_only.json create mode 100644 node_modules/domhandler/test/cases/13-comment_in_text.json create mode 100644 node_modules/domhandler/test/cases/14-comment_in_text_in_script.json create mode 100644 node_modules/domhandler/test/cases/15-non-verbose.json create mode 100644 node_modules/domhandler/test/cases/16-normalize_whitespace.json create mode 100644 node_modules/domhandler/test/cases/17-xml_namespace.json create mode 100644 node_modules/domhandler/test/cases/18-enforce_empty_tags.json create mode 100644 node_modules/domhandler/test/cases/19-ignore_empty_tags.json create mode 100644 node_modules/domhandler/test/cases/20-template_script_tags.json create mode 100644 node_modules/domhandler/test/cases/21-conditional_comments.json create mode 100644 node_modules/domhandler/test/cases/22-lowercase_tags.json create mode 100644 node_modules/domhandler/test/tests.js (limited to 'node_modules/domhandler') 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 " +} 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([ callback(err, dom), ] [ options ]); +// var parser = new Parser(handler[, options]); +``` + +##Example +```javascript +var htmlparser = require("htmlparser2"); +var rawHtml = "Xyz ", + "expected": [ + { + "type": "script", + "name": "script", + "attribs": {}, + "children": [ + { + "data": "", + "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": "", + "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": "the text", + "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": "the text", + "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": "