本时支付宝小程序
71
api/api.js
Executable file
@@ -0,0 +1,71 @@
|
|||||||
|
let apiUrl = "https://www.ysd-bs.com/api/",
|
||||||
|
timeout = 30000
|
||||||
|
|
||||||
|
let request = (obj) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
my.request({
|
||||||
|
url : apiUrl + obj.url || '',
|
||||||
|
headers : obj.header || { 'content-type': 'application/json' },
|
||||||
|
method : obj.method || 'GET',
|
||||||
|
data : obj.data || {},
|
||||||
|
timeout : timeout,
|
||||||
|
success : (res) => {
|
||||||
|
if (res.data.status_code == '200') {
|
||||||
|
resolve(res.data)
|
||||||
|
} else if (res.data.status_code == '401') {
|
||||||
|
my.showToast({
|
||||||
|
type : "fail",
|
||||||
|
content : "接口请求失败,未登录;err:" + res.data.message
|
||||||
|
});
|
||||||
|
}else {
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
fail : (err) => {
|
||||||
|
if(err.status == 401){
|
||||||
|
// 清理缓存
|
||||||
|
my.clearStorageSync()
|
||||||
|
// 清理全局数据
|
||||||
|
getApp().globalData.userInfo = {}
|
||||||
|
getApp().globalData.isUser = false
|
||||||
|
getApp().globalData.token = ""
|
||||||
|
// 提示信息
|
||||||
|
my.alert({
|
||||||
|
title : '提示',
|
||||||
|
content : '登录状态已过期,请重新登录',
|
||||||
|
success : res => {
|
||||||
|
my.redirectTo({
|
||||||
|
url: '../login/login'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
reject(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
let userinfo = (obj) => {
|
||||||
|
return request({
|
||||||
|
url : "users/info",
|
||||||
|
header : {
|
||||||
|
"Authorization": obj
|
||||||
|
},
|
||||||
|
method : "POST"
|
||||||
|
}).then(res=>{
|
||||||
|
getApp().globalData.userInfo = res.data
|
||||||
|
return res.data
|
||||||
|
}).catch(err=>{
|
||||||
|
my.showToast({
|
||||||
|
type : "fail",
|
||||||
|
content: "未登录,获取信息失败"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
request,
|
||||||
|
userinfo
|
||||||
|
}
|
||||||
74
app.acss
Executable file
@@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Web唐明明
|
||||||
|
* 一个梦想做木雕手艺人的程序员
|
||||||
|
*/
|
||||||
|
|
||||||
|
page {
|
||||||
|
background: white;
|
||||||
|
font-size: 28rpx;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 按钮 */
|
||||||
|
|
||||||
|
.btn{
|
||||||
|
background: #ff6600;
|
||||||
|
border-color: #ff6600;
|
||||||
|
color: white;
|
||||||
|
font-size: 32rpx;
|
||||||
|
height: 95rpx;
|
||||||
|
line-height: 95rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hover-btn{
|
||||||
|
background: #da5700;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 导航点击样式 */
|
||||||
|
.nav-hover{
|
||||||
|
background: rgba(0, 0, 0, .05);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 水平居中
|
||||||
|
*/
|
||||||
|
.pack-center {
|
||||||
|
display: -webkit-box;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-box-pack: center;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
top: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 文字截取
|
||||||
|
*/
|
||||||
|
|
||||||
|
.nowrap {
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
white-space: nowrap;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nowrap-multi {
|
||||||
|
display: -webkit-box;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
-webkit-box-orient: vertical;
|
||||||
|
-webkit-line-clamp: 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 分页加载
|
||||||
|
*/
|
||||||
|
|
||||||
|
.pages-login{
|
||||||
|
text-align: center;
|
||||||
|
color: gray;
|
||||||
|
padding: 30rpx 0;
|
||||||
|
}
|
||||||
20
app.js
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
App({
|
||||||
|
onLaunch(options) {
|
||||||
|
let userToken = my.getStorageSync({key:"userToken"}).data || null,
|
||||||
|
atTime = Math.round(new Date() / 1000)
|
||||||
|
|
||||||
|
if(userToken != null){
|
||||||
|
this.globalData.isUser = true
|
||||||
|
this.globalData.token = userToken.token
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onShow(options) {
|
||||||
|
|
||||||
|
},
|
||||||
|
globalData:{
|
||||||
|
isUser : false,
|
||||||
|
token : "",
|
||||||
|
expires : 0,
|
||||||
|
userInfo: {}
|
||||||
|
}
|
||||||
|
});
|
||||||
60
app.json
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
{
|
||||||
|
"pages": [
|
||||||
|
"pages/welcome/welcome",
|
||||||
|
"pages/login/login",
|
||||||
|
"pages/index/index",
|
||||||
|
"pages/set_meal/set_meal",
|
||||||
|
"pages/user/user",
|
||||||
|
"pages/sub_order/sub_order",
|
||||||
|
"pages/enter/enter",
|
||||||
|
"pages/find/find",
|
||||||
|
"pages/set/set",
|
||||||
|
"pages/shop_user/shop_user",
|
||||||
|
"pages/add_user/add_user",
|
||||||
|
"pages/order/order",
|
||||||
|
"pages/refund/refund",
|
||||||
|
"pages/refund_record/refund_record",
|
||||||
|
"pages/welfare/welfare",
|
||||||
|
"pages/welfare_list/welfare_list",
|
||||||
|
"pages/welfare_deta/welfare_deta",
|
||||||
|
"pages/changePwd/changePwd",
|
||||||
|
"pages/payCode/payCode",
|
||||||
|
"pages/results/results",
|
||||||
|
"pages/star_card/star_card",
|
||||||
|
"pages/equity/equity",
|
||||||
|
"pages/equity_list/equity_list",
|
||||||
|
"pages/wallet/wallet",
|
||||||
|
"pages/wallet_extract/wallet_extract",
|
||||||
|
"pages/logs/logs",
|
||||||
|
"pages/nuclear/nuclear",
|
||||||
|
"pages/nuclear_code/nuclear_code",
|
||||||
|
"pages/notice_date/notice_date",
|
||||||
|
"pages/gas_list/gas_list",
|
||||||
|
"pages/gas/gas",
|
||||||
|
"pages/stages_pay/stages_pay",
|
||||||
|
"pages/stages_form/stages_form"
|
||||||
|
],
|
||||||
|
"window": {
|
||||||
|
"defaultTitle": " ",
|
||||||
|
"pullRefresh": false,
|
||||||
|
"backgroundColor": "#fafafa"
|
||||||
|
},
|
||||||
|
"tabBar": {
|
||||||
|
"items": [
|
||||||
|
{
|
||||||
|
"pagePath": "pages/index/index",
|
||||||
|
"name": "工作台",
|
||||||
|
"icon": "lib/icon/tabBar_icon_00.png",
|
||||||
|
"activeIcon": "lib/icon/tabBar_active_00.png"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pagePath": "pages/user/user",
|
||||||
|
"name": "我的",
|
||||||
|
"icon": "lib/icon/tabBar_icon_02.png",
|
||||||
|
"activeIcon": "lib/icon/tabBar_active_02.png"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"selectedColor": "#ff6600",
|
||||||
|
"textColor": "#8a8a8a"
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
lib/icon/add_icon.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
lib/icon/arrows_dow.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
lib/icon/arrows_right.png
Executable file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
lib/icon/enter_code_icon.png
Executable file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
lib/icon/enter_phone_icon.png
Executable file
|
After Width: | Height: | Size: 1.1 KiB |
BIN
lib/icon/enter_shop_icon.png
Executable file
|
After Width: | Height: | Size: 1.2 KiB |
BIN
lib/icon/index_icon_00.png
Executable file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
lib/icon/index_icon_01.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/index_icon_02.png
Executable file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
lib/icon/index_icon_03.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/index_icon_04.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
lib/icon/list_null.png
Executable file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
lib/icon/login_pss_icon.png
Executable file
|
After Width: | Height: | Size: 909 B |
BIN
lib/icon/login_user_icon.png
Executable file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
lib/icon/month_icon.png
Executable file
|
After Width: | Height: | Size: 280 B |
BIN
lib/icon/permissions_icon.png
Executable file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
lib/icon/screen_calss.png
Executable file
|
After Width: | Height: | Size: 1.6 KiB |
BIN
lib/icon/screen_icon.png
Executable file
|
After Width: | Height: | Size: 955 B |
BIN
lib/icon/tabBar_active_00.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/tabBar_active_02.png
Executable file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
lib/icon/tabBar_icon_00.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/tabBar_icon_02.png
Executable file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
lib/icon/user_btn_icon_00.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
lib/icon/user_btn_icon_01.png
Executable file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
lib/icon/user_btn_icon_02.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
lib/icon/user_btn_icon_03.png
Executable file
|
After Width: | Height: | Size: 2.8 KiB |
BIN
lib/icon/user_btn_icon_04.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/user_btn_icon_05.png
Executable file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
lib/icon/user_btn_icon_06.png
Executable file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
lib/icon/welfareInfo_icon_00.png
Executable file
|
After Width: | Height: | Size: 726 B |
BIN
lib/icon/welfareInfo_icon_01.png
Executable file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
lib/icon/welfareInfo_icon_02.png
Executable file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
lib/icon/welfareInfo_icon_03.png
Executable file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
lib/icon/welfareInfo_icon_04.png
Executable file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
lib/icon/welfareInfo_icon_05.png
Executable file
|
After Width: | Height: | Size: 561 B |
BIN
lib/icon/welfareInfo_icon_06.png
Executable file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
lib/icon/welfareInfo_icon_07.png
Executable file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
lib/icon/welfareInfo_icon_08.png
Executable file
|
After Width: | Height: | Size: 3.4 KiB |
BIN
lib/icon/welfareInfo_icon_09.png
Executable file
|
After Width: | Height: | Size: 1.7 KiB |
BIN
lib/icon/welfareInfo_icon_10.png
Executable file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
lib/icon/welfareInfo_icon_11.png
Executable file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
lib/icon/welfareInfo_icon_12.png
Executable file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
lib/icon/welfareInfo_icon_13.png
Normal file
|
After Width: | Height: | Size: 779 B |
BIN
lib/icon/welfareInfo_icon_14.png
Normal file
|
After Width: | Height: | Size: 892 B |
BIN
lib/icon/welfareInfo_icon_15.png
Normal file
|
After Width: | Height: | Size: 913 B |
BIN
lib/icon/welfare_header_icon_00.png
Executable file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
lib/icon/welfare_header_icon_01.png
Executable file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
lib/img/banner_00.png
Executable file
|
After Width: | Height: | Size: 50 KiB |
BIN
lib/img/banner_01.png
Executable file
|
After Width: | Height: | Size: 42 KiB |
BIN
lib/img/banner_02.png
Executable file
|
After Width: | Height: | Size: 36 KiB |
BIN
lib/img/login_back.png
Executable file
|
After Width: | Height: | Size: 97 KiB |
BIN
lib/img/user_cover.png
Executable file
|
After Width: | Height: | Size: 4.2 KiB |
11
node_modules/domelementtype/LICENSE
generated
vendored
Executable file
@@ -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.
|
||||||
15
node_modules/domelementtype/index.js
generated
vendored
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
//Types of elements found in the DOM
|
||||||
|
module.exports = {
|
||||||
|
Text: "text", //Text
|
||||||
|
Directive: "directive", //<? ... ?>
|
||||||
|
Comment: "comment", //<!-- ... -->
|
||||||
|
Script: "script", //<script> tags
|
||||||
|
Style: "style", //<style> tags
|
||||||
|
Tag: "tag", //Any tag
|
||||||
|
CDATA: "cdata", //<![CDATA[ ... ]]>
|
||||||
|
Doctype: "doctype",
|
||||||
|
|
||||||
|
isTag: function(elem){
|
||||||
|
return elem.type === "tag" || elem.type === "script" || elem.type === "style";
|
||||||
|
}
|
||||||
|
};
|
||||||
48
node_modules/domelementtype/package.json
generated
vendored
Executable file
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"_from": "domelementtype@1",
|
||||||
|
"_id": "domelementtype@1.3.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-BSKB+TSpMpFI/HOxCNr1O8aMOTZ8hT3pM3GQ0w/mWRmkhEDSFJkkyzz4XQsBV44BChwGkrDfMyjVD0eA2aFV3w==",
|
||||||
|
"_location": "/domelementtype",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "domelementtype@1",
|
||||||
|
"name": "domelementtype",
|
||||||
|
"escapedName": "domelementtype",
|
||||||
|
"rawSpec": "1",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "1"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/domhandler"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-1.3.1.tgz",
|
||||||
|
"_shasum": "d048c44b37b0d10a7f2a3d5fee3f4333d790481f",
|
||||||
|
"_spec": "domelementtype@1",
|
||||||
|
"_where": "/Users/WebTmm/Documents/支付宝小程序/亿分期/node_modules/domhandler",
|
||||||
|
"author": {
|
||||||
|
"name": "Felix Boehm",
|
||||||
|
"email": "me@feedic.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/fb55/domelementtype/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "all the types of nodes in htmlparser2's dom",
|
||||||
|
"homepage": "https://github.com/fb55/domelementtype#readme",
|
||||||
|
"keywords": [
|
||||||
|
"dom",
|
||||||
|
"htmlparser2"
|
||||||
|
],
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "domelementtype",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/fb55/domelementtype.git"
|
||||||
|
},
|
||||||
|
"version": "1.3.1"
|
||||||
|
}
|
||||||
1
node_modules/domelementtype/readme.md
generated
vendored
Executable file
@@ -0,0 +1 @@
|
|||||||
|
all the types of nodes in htmlparser2's dom
|
||||||
6
node_modules/domhandler/.travis.yml
generated
vendored
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
before_install:
|
||||||
|
- '[ "${TRAVIS_NODE_VERSION}" != "0.8" ] || npm install -g npm@1.4.28'
|
||||||
|
- npm install -g npm@latest
|
||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- 8
|
||||||
11
node_modules/domhandler/LICENSE
generated
vendored
Executable file
@@ -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.
|
||||||
217
node_modules/domhandler/index.js
generated
vendored
Executable file
@@ -0,0 +1,217 @@
|
|||||||
|
var ElementType = require("domelementtype");
|
||||||
|
|
||||||
|
var re_whitespace = /\s+/g;
|
||||||
|
var NodePrototype = require("./lib/node");
|
||||||
|
var ElementPrototype = require("./lib/element");
|
||||||
|
|
||||||
|
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 = [];
|
||||||
|
this._parser = this._parser || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//default options
|
||||||
|
var defaultOpts = {
|
||||||
|
normalizeWhitespace: false, //Replace all whitespace with single spaces
|
||||||
|
withStartIndices: false, //Add startIndex properties to nodes
|
||||||
|
withEndIndices: false, //Add endIndex properties to nodes
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.onparserinit = function(parser){
|
||||||
|
this._parser = parser;
|
||||||
|
};
|
||||||
|
|
||||||
|
//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._parser = null;
|
||||||
|
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(){
|
||||||
|
//if(this._tagStack.pop().name !== name) this._handleCallback(Error("Tagname didn't match!"));
|
||||||
|
|
||||||
|
var elem = this._tagStack.pop();
|
||||||
|
|
||||||
|
if(this._options.withEndIndices && elem){
|
||||||
|
elem.endIndex = this._parser.endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(this._elementCB) this._elementCB(elem);
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype._createDomElement = function(properties){
|
||||||
|
if (!this._options.withDomLvl1) return properties;
|
||||||
|
|
||||||
|
var element;
|
||||||
|
if (properties.type === "tag") {
|
||||||
|
element = Object.create(ElementPrototype);
|
||||||
|
} else {
|
||||||
|
element = Object.create(NodePrototype);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var key in properties) {
|
||||||
|
if (properties.hasOwnProperty(key)) {
|
||||||
|
element[key] = properties[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype._addDomElement = function(element){
|
||||||
|
var parent = this._tagStack[this._tagStack.length - 1];
|
||||||
|
var siblings = parent ? parent.children : this.dom;
|
||||||
|
var previousSibling = siblings[siblings.length - 1];
|
||||||
|
|
||||||
|
element.next = null;
|
||||||
|
|
||||||
|
if(this._options.withStartIndices){
|
||||||
|
element.startIndex = this._parser.startIndex;
|
||||||
|
}
|
||||||
|
if(this._options.withEndIndices){
|
||||||
|
element.endIndex = this._parser.endIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(previousSibling){
|
||||||
|
element.prev = previousSibling;
|
||||||
|
previousSibling.next = element;
|
||||||
|
} else {
|
||||||
|
element.prev = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
siblings.push(element);
|
||||||
|
element.parent = parent || null;
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.onopentag = function(name, attribs){
|
||||||
|
var properties = {
|
||||||
|
type: name === "script" ? ElementType.Script : name === "style" ? ElementType.Style : ElementType.Tag,
|
||||||
|
name: name,
|
||||||
|
attribs: attribs,
|
||||||
|
children: []
|
||||||
|
};
|
||||||
|
|
||||||
|
var element = this._createDomElement(properties);
|
||||||
|
|
||||||
|
this._addDomElement(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, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = this._createDomElement({
|
||||||
|
data: data,
|
||||||
|
type: ElementType.Text
|
||||||
|
});
|
||||||
|
|
||||||
|
this._addDomElement(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.oncomment = function(data){
|
||||||
|
var lastTag = this._tagStack[this._tagStack.length - 1];
|
||||||
|
|
||||||
|
if(lastTag && lastTag.type === ElementType.Comment){
|
||||||
|
lastTag.data += data;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var properties = {
|
||||||
|
data: data,
|
||||||
|
type: ElementType.Comment
|
||||||
|
};
|
||||||
|
|
||||||
|
var element = this._createDomElement(properties);
|
||||||
|
|
||||||
|
this._addDomElement(element);
|
||||||
|
this._tagStack.push(element);
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.oncdatastart = function(){
|
||||||
|
var properties = {
|
||||||
|
children: [{
|
||||||
|
data: "",
|
||||||
|
type: ElementType.Text
|
||||||
|
}],
|
||||||
|
type: ElementType.CDATA
|
||||||
|
};
|
||||||
|
|
||||||
|
var element = this._createDomElement(properties);
|
||||||
|
|
||||||
|
this._addDomElement(element);
|
||||||
|
this._tagStack.push(element);
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.oncommentend = DomHandler.prototype.oncdataend = function(){
|
||||||
|
this._tagStack.pop();
|
||||||
|
};
|
||||||
|
|
||||||
|
DomHandler.prototype.onprocessinginstruction = function(name, data){
|
||||||
|
var element = this._createDomElement({
|
||||||
|
name: name,
|
||||||
|
data: data,
|
||||||
|
type: ElementType.Directive
|
||||||
|
});
|
||||||
|
|
||||||
|
this._addDomElement(element);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = DomHandler;
|
||||||
20
node_modules/domhandler/lib/element.js
generated
vendored
Executable file
@@ -0,0 +1,20 @@
|
|||||||
|
// DOM-Level-1-compliant structure
|
||||||
|
var NodePrototype = require('./node');
|
||||||
|
var ElementPrototype = module.exports = Object.create(NodePrototype);
|
||||||
|
|
||||||
|
var domLvl1 = {
|
||||||
|
tagName: "name"
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(domLvl1).forEach(function(key) {
|
||||||
|
var shorthand = domLvl1[key];
|
||||||
|
Object.defineProperty(ElementPrototype, key, {
|
||||||
|
get: function() {
|
||||||
|
return this[shorthand] || null;
|
||||||
|
},
|
||||||
|
set: function(val) {
|
||||||
|
this[shorthand] = val;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
44
node_modules/domhandler/lib/node.js
generated
vendored
Executable file
@@ -0,0 +1,44 @@
|
|||||||
|
// This object will be used as the prototype for Nodes when creating a
|
||||||
|
// DOM-Level-1-compliant structure.
|
||||||
|
var NodePrototype = module.exports = {
|
||||||
|
get firstChild() {
|
||||||
|
var children = this.children;
|
||||||
|
return children && children[0] || null;
|
||||||
|
},
|
||||||
|
get lastChild() {
|
||||||
|
var children = this.children;
|
||||||
|
return children && children[children.length - 1] || null;
|
||||||
|
},
|
||||||
|
get nodeType() {
|
||||||
|
return nodeTypes[this.type] || nodeTypes.element;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var domLvl1 = {
|
||||||
|
tagName: "name",
|
||||||
|
childNodes: "children",
|
||||||
|
parentNode: "parent",
|
||||||
|
previousSibling: "prev",
|
||||||
|
nextSibling: "next",
|
||||||
|
nodeValue: "data"
|
||||||
|
};
|
||||||
|
|
||||||
|
var nodeTypes = {
|
||||||
|
element: 1,
|
||||||
|
text: 3,
|
||||||
|
cdata: 4,
|
||||||
|
comment: 8
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(domLvl1).forEach(function(key) {
|
||||||
|
var shorthand = domLvl1[key];
|
||||||
|
Object.defineProperty(NodePrototype, key, {
|
||||||
|
get: function() {
|
||||||
|
return this[shorthand] || null;
|
||||||
|
},
|
||||||
|
set: function(val) {
|
||||||
|
this[shorthand] = val;
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
73
node_modules/domhandler/package.json
generated
vendored
Executable file
@@ -0,0 +1,73 @@
|
|||||||
|
{
|
||||||
|
"_from": "domhandler@^2.4.2",
|
||||||
|
"_id": "domhandler@2.4.2",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-JiK04h0Ht5u/80fdLMCEmV4zkNh2BcoMFBmZ/91WtYZ8qVXSKjiw7fXMgFPnHcSZgOo3XdinHvmnDUeMf5R4wA==",
|
||||||
|
"_location": "/domhandler",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "domhandler@^2.4.2",
|
||||||
|
"name": "domhandler",
|
||||||
|
"escapedName": "domhandler",
|
||||||
|
"rawSpec": "^2.4.2",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^2.4.2"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/mini-html-parser2"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/domhandler/-/domhandler-2.4.2.tgz",
|
||||||
|
"_shasum": "8805097e933d65e85546f726d60f5eb88b44f803",
|
||||||
|
"_spec": "domhandler@^2.4.2",
|
||||||
|
"_where": "/Users/WebTmm/Documents/支付宝小程序/亿分期/node_modules/mini-html-parser2",
|
||||||
|
"author": {
|
||||||
|
"name": "Felix Boehm",
|
||||||
|
"email": "me@feedic.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/fb55/DomHandler/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"domelementtype": "1"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "handler for htmlparser2 that turns pages into a dom",
|
||||||
|
"devDependencies": {
|
||||||
|
"htmlparser2": "^3.9.0",
|
||||||
|
"jshint": "^2.9.1",
|
||||||
|
"mocha": "^3.0.2"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"test": "tests"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/fb55/DomHandler#readme",
|
||||||
|
"jshintConfig": {
|
||||||
|
"quotmark": "double",
|
||||||
|
"trailing": true,
|
||||||
|
"unused": true,
|
||||||
|
"undef": true,
|
||||||
|
"node": true,
|
||||||
|
"proto": true,
|
||||||
|
"globals": {
|
||||||
|
"it": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"keywords": [
|
||||||
|
"dom",
|
||||||
|
"htmlparser2"
|
||||||
|
],
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "domhandler",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/fb55/DomHandler.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "mocha -R list && jshint index.js test/"
|
||||||
|
},
|
||||||
|
"version": "2.4.2"
|
||||||
|
}
|
||||||
116
node_modules/domhandler/readme.md
generated
vendored
Executable file
@@ -0,0 +1,116 @@
|
|||||||
|
# domhandler [](https://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](https://github.com/fb55/domutils) library.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```javascript
|
||||||
|
var handler = new DomHandler([ <func> callback(err, dom), ] [ <obj> options ]);
|
||||||
|
// var parser = new Parser(handler[, options]);
|
||||||
|
```
|
||||||
|
|
||||||
|
Available options are described below.
|
||||||
|
|
||||||
|
## 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.end();
|
||||||
|
```
|
||||||
|
|
||||||
|
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: normalizeWhitespace
|
||||||
|
Indicates whether the whitespace in text nodes should be normalized (= all whitespace should be replaced with single spaces). 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: [{
|
||||||
|
data: ' ',
|
||||||
|
type: 'text'
|
||||||
|
}, {
|
||||||
|
type: 'tag',
|
||||||
|
name: 'br'
|
||||||
|
}, {
|
||||||
|
data: 'this is the text ',
|
||||||
|
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'
|
||||||
|
}]
|
||||||
|
}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Option: withDomLvl1
|
||||||
|
|
||||||
|
Adds DOM level 1 properties to all elements.
|
||||||
|
|
||||||
|
<!-- TODO: description -->
|
||||||
|
|
||||||
|
## Option: withStartIndices
|
||||||
|
Indicates whether a `startIndex` property will be added to nodes. When the parser is used in a non-streaming fashion, `startIndex` is an integer indicating the position of the start of the node in the document. The default value is "false".
|
||||||
|
|
||||||
|
## Option: withEndIndices
|
||||||
|
Indicates whether a `endIndex` property will be added to nodes. When the parser is used in a non-streaming fashion, `endIndex` is an integer indicating the position of the end of the node in the document. The default value is "false".
|
||||||
57
node_modules/domhandler/test/cases/01-basic.json
generated
vendored
Executable file
@@ -0,0 +1,57 @@
|
|||||||
|
{
|
||||||
|
"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": {},
|
||||||
|
"parent": null,
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"name": "title",
|
||||||
|
"attribs": {},
|
||||||
|
"parent": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "html",
|
||||||
|
"attribs": {}
|
||||||
|
},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"data": "The Title",
|
||||||
|
"type": "text",
|
||||||
|
"parent": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "title",
|
||||||
|
"attribs": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"name": "body",
|
||||||
|
"attribs": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"data": "Hello world",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"prev": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "title",
|
||||||
|
"attribs": {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
21
node_modules/domhandler/test/cases/02-single_tag_1.json
generated
vendored
Executable file
@@ -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": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
21
node_modules/domhandler/test/cases/03-single_tag_2.json
generated
vendored
Executable file
@@ -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": {}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
27
node_modules/domhandler/test/cases/04-unescaped_in_script.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
node_modules/domhandler/test/cases/05-tags_in_comment.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
node_modules/domhandler/test/cases/06-comment_in_script.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
node_modules/domhandler/test/cases/07-unescaped_in_style.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
node_modules/domhandler/test/cases/08-extra_spaces_in_tag.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
node_modules/domhandler/test/cases/09-unquoted_attrib.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
15
node_modules/domhandler/test/cases/10-singular_attribute.json
generated
vendored
Executable file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"name": "Singular attribute",
|
||||||
|
"options": {},
|
||||||
|
"html": "<option value='foo' selected>",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"name": "option",
|
||||||
|
"attribs": {
|
||||||
|
"value": "foo",
|
||||||
|
"selected": ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
40
node_modules/domhandler/test/cases/11-text_outside_tags.json
generated
vendored
Executable file
@@ -0,0 +1,40 @@
|
|||||||
|
{
|
||||||
|
"name": "Text outside tags",
|
||||||
|
"options": {},
|
||||||
|
"html": "Line one\n<br>\nline two",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"data": "Line one\n",
|
||||||
|
"type": "text",
|
||||||
|
"prev": null,
|
||||||
|
"next": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "br",
|
||||||
|
"attribs": {}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"name": "br",
|
||||||
|
"attribs": {},
|
||||||
|
"prev": {
|
||||||
|
"data": "Line one\n",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
"next": {
|
||||||
|
"data": "\nline two",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": "\nline two",
|
||||||
|
"type": "text",
|
||||||
|
"prev": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "br",
|
||||||
|
"attribs": {}
|
||||||
|
},
|
||||||
|
"next": null
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
11
node_modules/domhandler/test/cases/12-text_only.json
generated
vendored
Executable file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"name": "Only text",
|
||||||
|
"options": {},
|
||||||
|
"html": "this is the text",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"data": "this is the text",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
19
node_modules/domhandler/test/cases/13-comment_in_text.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
node_modules/domhandler/test/cases/14-comment_in_text_in_script.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
22
node_modules/domhandler/test/cases/15-non-verbose.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
47
node_modules/domhandler/test/cases/16-normalize_whitespace.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
18
node_modules/domhandler/test/cases/17-xml_namespace.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
16
node_modules/domhandler/test/cases/18-enforce_empty_tags.json
generated
vendored
Executable file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"name": "Enforce empty tags",
|
||||||
|
"options": {},
|
||||||
|
"html": "<link>text</link>",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"name": "link",
|
||||||
|
"attribs": {}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"data": "text",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
node_modules/domhandler/test/cases/19-ignore_empty_tags.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
20
node_modules/domhandler/test/cases/20-template_script_tags.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
15
node_modules/domhandler/test/cases/21-conditional_comments.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
41
node_modules/domhandler/test/cases/22-lowercase_tags.json
generated
vendored
Executable file
@@ -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"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
131
node_modules/domhandler/test/cases/23-dom-lvl1.json
generated
vendored
Executable file
@@ -0,0 +1,131 @@
|
|||||||
|
{
|
||||||
|
"name": "DOM level 1",
|
||||||
|
"options": { "withDomLvl1": true },
|
||||||
|
"html": "<div>some stray text<h1>Hello, world.</h1><!-- comment node -->more stray text</div>",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"nodeType": 1,
|
||||||
|
"name": "div",
|
||||||
|
"tagName": "div",
|
||||||
|
"attribs": {},
|
||||||
|
"nodeValue": null,
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "some stray text",
|
||||||
|
"nodeValue": "some stray text",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "tag",
|
||||||
|
"nodeType": 1,
|
||||||
|
"name": "h1",
|
||||||
|
"tagName": "h1",
|
||||||
|
"nodeValue": null,
|
||||||
|
"attribs": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "Hello, world.",
|
||||||
|
"nodeValue": "Hello, world.",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"firstChild": {
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "Hello, world.",
|
||||||
|
"nodeValue": "Hello, world.",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
},
|
||||||
|
"lastChild": {
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "Hello, world.",
|
||||||
|
"nodeValue": "Hello, world.",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "comment",
|
||||||
|
"nodeType": 8,
|
||||||
|
"tagName": null,
|
||||||
|
"data": " comment node ",
|
||||||
|
"nodeValue": " comment node ",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null,
|
||||||
|
"prev": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "h1",
|
||||||
|
"nodeValue": null,
|
||||||
|
"attribs": {}
|
||||||
|
},
|
||||||
|
"previousSibling": {
|
||||||
|
"type": "tag",
|
||||||
|
"name": "h1",
|
||||||
|
"nodeValue": null,
|
||||||
|
"attribs": {}
|
||||||
|
},
|
||||||
|
"next": {
|
||||||
|
"type": "text",
|
||||||
|
"tagName": null,
|
||||||
|
"data": "more stray text"
|
||||||
|
},
|
||||||
|
"nextSibling": {
|
||||||
|
"type": "text",
|
||||||
|
"tagName": null,
|
||||||
|
"data": "more stray text"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "more stray text",
|
||||||
|
"nodeValue": "more stray text",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null,
|
||||||
|
"next": null,
|
||||||
|
"nextSibling": null
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"firstChild": {
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "some stray text",
|
||||||
|
"nodeValue": "some stray text",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
},
|
||||||
|
"lastChild": {
|
||||||
|
"type": "text",
|
||||||
|
"nodeType": 3,
|
||||||
|
"tagName": null,
|
||||||
|
"data": "more stray text",
|
||||||
|
"nodeValue": "more stray text",
|
||||||
|
"childNodes": null,
|
||||||
|
"firstChild": null,
|
||||||
|
"lastChild": null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
85
node_modules/domhandler/test/cases/24-with-start-indices.json
generated
vendored
Executable file
@@ -0,0 +1,85 @@
|
|||||||
|
{
|
||||||
|
"name": "withStartIndices adds correct startIndex properties",
|
||||||
|
"options": {"withStartIndices": true},
|
||||||
|
"streaming": false,
|
||||||
|
"html": "<!DOCTYPE html> <html> <title>The Title</title> <body class='foo'>Hello world <p></p></body> <!-- the comment --> </html> ",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"startIndex": 0,
|
||||||
|
"name": "!doctype",
|
||||||
|
"data": "!DOCTYPE html",
|
||||||
|
"type": "directive"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 16,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "html",
|
||||||
|
"attribs": {},
|
||||||
|
"parent": null,
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"startIndex": 22,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 23,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "title",
|
||||||
|
"attribs": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"startIndex": 30,
|
||||||
|
"data": "The Title",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 47,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 48,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "body",
|
||||||
|
"attribs": {"class": "foo"},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"startIndex": 66,
|
||||||
|
"data": "Hello world ",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 78,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "p",
|
||||||
|
"attribs": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 92,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 93,
|
||||||
|
"type": "comment",
|
||||||
|
"data": " the comment "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"startIndex": 113,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
86
node_modules/domhandler/test/cases/25-with-end-indices.json
generated
vendored
Executable file
@@ -0,0 +1,86 @@
|
|||||||
|
{
|
||||||
|
"name": "withEndIndices adds correct endIndex properties",
|
||||||
|
"options": {"withStartIndices": true,"withEndIndices": true},
|
||||||
|
"streaming": false,
|
||||||
|
"html": "<!DOCTYPE html> <html> <title>The Title</title> <body class='foo'>Hello world <p></p></body> <!-- the comment --> </html> ",
|
||||||
|
"expected": [
|
||||||
|
{
|
||||||
|
"endIndex": null,
|
||||||
|
"name": "!doctype",
|
||||||
|
"data": "!DOCTYPE html",
|
||||||
|
"type": "directive"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "text",
|
||||||
|
"data": " ",
|
||||||
|
"endIndex": 15
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 120,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "html",
|
||||||
|
"attribs": {},
|
||||||
|
"parent": null,
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"endIndex": 22,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 46,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "title",
|
||||||
|
"attribs": {},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"endIndex": 38,
|
||||||
|
"data": "The Title",
|
||||||
|
"type": "text"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 47,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 91,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "body",
|
||||||
|
"attribs": {"class": "foo"},
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"endIndex": 77,
|
||||||
|
"data": "Hello world ",
|
||||||
|
"type": "text"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 84,
|
||||||
|
"type": "tag",
|
||||||
|
"name": "p",
|
||||||
|
"attribs": {},
|
||||||
|
"children": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 92,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 112,
|
||||||
|
"type": "comment",
|
||||||
|
"data": " the comment "
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"endIndex": 113,
|
||||||
|
"type": "text",
|
||||||
|
"data": " "
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
60
node_modules/domhandler/test/tests.js
generated
vendored
Executable file
@@ -0,0 +1,60 @@
|
|||||||
|
var fs = require("fs"),
|
||||||
|
path = require("path"),
|
||||||
|
assert = require("assert"),
|
||||||
|
util = require("util"),
|
||||||
|
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
|
||||||
|
if (test.streaming || test.streaming === undefined){
|
||||||
|
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]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
5
node_modules/entities/.travis.yml
generated
vendored
Executable file
@@ -0,0 +1,5 @@
|
|||||||
|
sudo: true
|
||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- 8
|
||||||
|
script: npm run coveralls
|
||||||
11
node_modules/entities/LICENSE
generated
vendored
Executable file
@@ -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.
|
||||||
26
node_modules/entities/index.js
generated
vendored
Executable file
@@ -0,0 +1,26 @@
|
|||||||
|
var encode = require("./lib/encode.js"),
|
||||||
|
decode = require("./lib/decode.js");
|
||||||
|
|
||||||
|
exports.decode = function(data, level) {
|
||||||
|
return (!level || level <= 0 ? decode.XML : decode.HTML)(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.decodeStrict = function(data, level) {
|
||||||
|
return (!level || level <= 0 ? decode.XML : decode.HTMLStrict)(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.encode = function(data, level) {
|
||||||
|
return (!level || level <= 0 ? encode.XML : encode.HTML)(data);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.encodeXML = encode.XML;
|
||||||
|
|
||||||
|
exports.encodeHTML4 = exports.encodeHTML5 = exports.encodeHTML = encode.HTML;
|
||||||
|
|
||||||
|
exports.decodeXML = exports.decodeXMLStrict = decode.XML;
|
||||||
|
|
||||||
|
exports.decodeHTML4 = exports.decodeHTML5 = exports.decodeHTML = decode.HTML;
|
||||||
|
|
||||||
|
exports.decodeHTML4Strict = exports.decodeHTML5Strict = exports.decodeHTMLStrict = decode.HTMLStrict;
|
||||||
|
|
||||||
|
exports.escape = encode.escape;
|
||||||
70
node_modules/entities/lib/decode.js
generated
vendored
Executable file
@@ -0,0 +1,70 @@
|
|||||||
|
var entityMap = require("../maps/entities.json"),
|
||||||
|
legacyMap = require("../maps/legacy.json"),
|
||||||
|
xmlMap = require("../maps/xml.json"),
|
||||||
|
decodeCodePoint = require("./decode_codepoint.js");
|
||||||
|
|
||||||
|
var decodeXMLStrict = getStrictDecoder(xmlMap),
|
||||||
|
decodeHTMLStrict = getStrictDecoder(entityMap);
|
||||||
|
|
||||||
|
function getStrictDecoder(map) {
|
||||||
|
var keys = Object.keys(map).join("|"),
|
||||||
|
replace = getReplacer(map);
|
||||||
|
|
||||||
|
keys += "|#[xX][\\da-fA-F]+|#\\d+";
|
||||||
|
|
||||||
|
var re = new RegExp("&(?:" + keys + ");", "g");
|
||||||
|
|
||||||
|
return function(str) {
|
||||||
|
return String(str).replace(re, replace);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var decodeHTML = (function() {
|
||||||
|
var legacy = Object.keys(legacyMap).sort(sorter);
|
||||||
|
|
||||||
|
var keys = Object.keys(entityMap).sort(sorter);
|
||||||
|
|
||||||
|
for (var i = 0, j = 0; i < keys.length; i++) {
|
||||||
|
if (legacy[j] === keys[i]) {
|
||||||
|
keys[i] += ";?";
|
||||||
|
j++;
|
||||||
|
} else {
|
||||||
|
keys[i] += ";";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var re = new RegExp("&(?:" + keys.join("|") + "|#[xX][\\da-fA-F]+;?|#\\d+;?)", "g"),
|
||||||
|
replace = getReplacer(entityMap);
|
||||||
|
|
||||||
|
function replacer(str) {
|
||||||
|
if (str.substr(-1) !== ";") str += ";";
|
||||||
|
return replace(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO consider creating a merged map
|
||||||
|
return function(str) {
|
||||||
|
return String(str).replace(re, replacer);
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
|
function sorter(a, b) {
|
||||||
|
return a < b ? 1 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getReplacer(map) {
|
||||||
|
return function replace(str) {
|
||||||
|
if (str.charAt(1) === "#") {
|
||||||
|
if (str.charAt(2) === "X" || str.charAt(2) === "x") {
|
||||||
|
return decodeCodePoint(parseInt(str.substr(3), 16));
|
||||||
|
}
|
||||||
|
return decodeCodePoint(parseInt(str.substr(2), 10));
|
||||||
|
}
|
||||||
|
return map[str.slice(1, -1)];
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
XML: decodeXMLStrict,
|
||||||
|
HTML: decodeHTML,
|
||||||
|
HTMLStrict: decodeHTMLStrict
|
||||||
|
};
|
||||||
25
node_modules/entities/lib/decode_codepoint.js
generated
vendored
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
var decodeMap = require("../maps/decode.json");
|
||||||
|
|
||||||
|
module.exports = decodeCodePoint;
|
||||||
|
|
||||||
|
// modified version of https://github.com/mathiasbynens/he/blob/master/src/he.js#L94-L119
|
||||||
|
function decodeCodePoint(codePoint) {
|
||||||
|
if ((codePoint >= 0xd800 && codePoint <= 0xdfff) || codePoint > 0x10ffff) {
|
||||||
|
return "\uFFFD";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (codePoint in decodeMap) {
|
||||||
|
codePoint = decodeMap[codePoint];
|
||||||
|
}
|
||||||
|
|
||||||
|
var output = "";
|
||||||
|
|
||||||
|
if (codePoint > 0xffff) {
|
||||||
|
codePoint -= 0x10000;
|
||||||
|
output += String.fromCharCode(((codePoint >>> 10) & 0x3ff) | 0xd800);
|
||||||
|
codePoint = 0xdc00 | (codePoint & 0x3ff);
|
||||||
|
}
|
||||||
|
|
||||||
|
output += String.fromCharCode(codePoint);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
82
node_modules/entities/lib/encode.js
generated
vendored
Executable file
@@ -0,0 +1,82 @@
|
|||||||
|
var inverseXML = getInverseObj(require("../maps/xml.json")),
|
||||||
|
xmlReplacer = getInverseReplacer(inverseXML);
|
||||||
|
|
||||||
|
exports.XML = getInverse(inverseXML, xmlReplacer);
|
||||||
|
|
||||||
|
var inverseHTML = getInverseObj(require("../maps/entities.json")),
|
||||||
|
htmlReplacer = getInverseReplacer(inverseHTML);
|
||||||
|
|
||||||
|
exports.HTML = getInverse(inverseHTML, htmlReplacer);
|
||||||
|
|
||||||
|
function getInverseObj(obj) {
|
||||||
|
return Object.keys(obj)
|
||||||
|
.sort()
|
||||||
|
.reduce(function(inverse, name) {
|
||||||
|
inverse[obj[name]] = "&" + name + ";";
|
||||||
|
return inverse;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInverseReplacer(inverse) {
|
||||||
|
var single = [],
|
||||||
|
multiple = [];
|
||||||
|
|
||||||
|
Object.keys(inverse).forEach(function(k) {
|
||||||
|
if (k.length === 1) {
|
||||||
|
single.push("\\" + k);
|
||||||
|
} else {
|
||||||
|
multiple.push(k);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//TODO add ranges
|
||||||
|
multiple.unshift("[" + single.join("") + "]");
|
||||||
|
|
||||||
|
return new RegExp(multiple.join("|"), "g");
|
||||||
|
}
|
||||||
|
|
||||||
|
var re_nonASCII = /[^\0-\x7F]/g,
|
||||||
|
re_astralSymbols = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
|
||||||
|
|
||||||
|
function singleCharReplacer(c) {
|
||||||
|
return (
|
||||||
|
"&#x" +
|
||||||
|
c
|
||||||
|
.charCodeAt(0)
|
||||||
|
.toString(16)
|
||||||
|
.toUpperCase() +
|
||||||
|
";"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function astralReplacer(c) {
|
||||||
|
// http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
|
||||||
|
var high = c.charCodeAt(0);
|
||||||
|
var low = c.charCodeAt(1);
|
||||||
|
var codePoint = (high - 0xd800) * 0x400 + low - 0xdc00 + 0x10000;
|
||||||
|
return "&#x" + codePoint.toString(16).toUpperCase() + ";";
|
||||||
|
}
|
||||||
|
|
||||||
|
function getInverse(inverse, re) {
|
||||||
|
function func(name) {
|
||||||
|
return inverse[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
return function(data) {
|
||||||
|
return data
|
||||||
|
.replace(re, func)
|
||||||
|
.replace(re_astralSymbols, astralReplacer)
|
||||||
|
.replace(re_nonASCII, singleCharReplacer);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var re_xmlChars = getInverseReplacer(inverseXML);
|
||||||
|
|
||||||
|
function escapeXML(data) {
|
||||||
|
return data
|
||||||
|
.replace(re_xmlChars, singleCharReplacer)
|
||||||
|
.replace(re_astralSymbols, astralReplacer)
|
||||||
|
.replace(re_nonASCII, singleCharReplacer);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.escape = escapeXML;
|
||||||