@depup/cheerio 1.2.0-depup.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/Readme.md +229 -0
- package/changes.json +30 -0
- package/dist/browser/api/attributes.d.ts +385 -0
- package/dist/browser/api/attributes.d.ts.map +1 -0
- package/dist/browser/api/attributes.js +636 -0
- package/dist/browser/api/attributes.js.map +1 -0
- package/dist/browser/api/css.d.ts +42 -0
- package/dist/browser/api/css.d.ts.map +1 -0
- package/dist/browser/api/css.js +116 -0
- package/dist/browser/api/css.js.map +1 -0
- package/dist/browser/api/extract.d.ts +27 -0
- package/dist/browser/api/extract.d.ts.map +1 -0
- package/dist/browser/api/extract.js +42 -0
- package/dist/browser/api/extract.js.map +1 -0
- package/dist/browser/api/forms.d.ts +36 -0
- package/dist/browser/api/forms.d.ts.map +1 -0
- package/dist/browser/api/forms.js +81 -0
- package/dist/browser/api/forms.js.map +1 -0
- package/dist/browser/api/manipulation.d.ts +528 -0
- package/dist/browser/api/manipulation.d.ts.map +1 -0
- package/dist/browser/api/manipulation.js +831 -0
- package/dist/browser/api/manipulation.js.map +1 -0
- package/dist/browser/api/traversing.d.ts +657 -0
- package/dist/browser/api/traversing.d.ts.map +1 -0
- package/dist/browser/api/traversing.js +857 -0
- package/dist/browser/api/traversing.js.map +1 -0
- package/dist/browser/cheerio.d.ts +85 -0
- package/dist/browser/cheerio.d.ts.map +1 -0
- package/dist/browser/cheerio.js +58 -0
- package/dist/browser/cheerio.js.map +1 -0
- package/dist/browser/index-browser.d.mts.map +1 -0
- package/dist/browser/index-browser.mjs.map +1 -0
- package/dist/browser/index.d.ts +5 -0
- package/dist/browser/index.js +3 -0
- package/dist/browser/load-parse.d.ts +20 -0
- package/dist/browser/load-parse.d.ts.map +1 -0
- package/dist/browser/load-parse.js +28 -0
- package/dist/browser/load-parse.js.map +1 -0
- package/dist/browser/load.d.ts +91 -0
- package/dist/browser/load.d.ts.map +1 -0
- package/dist/browser/load.js +129 -0
- package/dist/browser/load.js.map +1 -0
- package/dist/browser/options.d.ts +98 -0
- package/dist/browser/options.d.ts.map +1 -0
- package/dist/browser/options.js +34 -0
- package/dist/browser/options.js.map +1 -0
- package/dist/browser/package.json +3 -0
- package/dist/browser/parse.d.ts +18 -0
- package/dist/browser/parse.d.ts.map +1 -0
- package/dist/browser/parse.js +73 -0
- package/dist/browser/parse.js.map +1 -0
- package/dist/browser/parsers/parse5-adapter.d.ts +20 -0
- package/dist/browser/parsers/parse5-adapter.d.ts.map +1 -0
- package/dist/browser/parsers/parse5-adapter.js +50 -0
- package/dist/browser/parsers/parse5-adapter.js.map +1 -0
- package/dist/browser/slim.d.ts +25 -0
- package/dist/browser/slim.d.ts.map +1 -0
- package/dist/browser/slim.js +22 -0
- package/dist/browser/slim.js.map +1 -0
- package/dist/browser/static.d.ts +112 -0
- package/dist/browser/static.d.ts.map +1 -0
- package/dist/browser/static.js +204 -0
- package/dist/browser/static.js.map +1 -0
- package/dist/browser/types.d.ts +21 -0
- package/dist/browser/types.d.ts.map +1 -0
- package/dist/browser/types.js +3 -0
- package/dist/browser/types.js.map +1 -0
- package/dist/browser/utils.d.ts +55 -0
- package/dist/browser/utils.d.ts.map +1 -0
- package/dist/browser/utils.js +84 -0
- package/dist/browser/utils.js.map +1 -0
- package/dist/commonjs/api/attributes.d.ts +385 -0
- package/dist/commonjs/api/attributes.d.ts.map +1 -0
- package/dist/commonjs/api/attributes.js +647 -0
- package/dist/commonjs/api/attributes.js.map +1 -0
- package/dist/commonjs/api/css.d.ts +42 -0
- package/dist/commonjs/api/css.d.ts.map +1 -0
- package/dist/commonjs/api/css.js +119 -0
- package/dist/commonjs/api/css.js.map +1 -0
- package/dist/commonjs/api/extract.d.ts +27 -0
- package/dist/commonjs/api/extract.d.ts.map +1 -0
- package/dist/commonjs/api/extract.js +45 -0
- package/dist/commonjs/api/extract.js.map +1 -0
- package/dist/commonjs/api/forms.d.ts +36 -0
- package/dist/commonjs/api/forms.d.ts.map +1 -0
- package/dist/commonjs/api/forms.js +85 -0
- package/dist/commonjs/api/forms.js.map +1 -0
- package/dist/commonjs/api/manipulation.d.ts +528 -0
- package/dist/commonjs/api/manipulation.d.ts.map +1 -0
- package/dist/commonjs/api/manipulation.js +850 -0
- package/dist/commonjs/api/manipulation.js.map +1 -0
- package/dist/commonjs/api/traversing.d.ts +657 -0
- package/dist/commonjs/api/traversing.d.ts.map +1 -0
- package/dist/commonjs/api/traversing.js +914 -0
- package/dist/commonjs/api/traversing.js.map +1 -0
- package/dist/commonjs/cheerio.d.ts +85 -0
- package/dist/commonjs/cheerio.d.ts.map +1 -0
- package/dist/commonjs/cheerio.js +95 -0
- package/dist/commonjs/cheerio.js.map +1 -0
- package/dist/commonjs/index.d.ts +104 -0
- package/dist/commonjs/index.d.ts.map +1 -0
- package/dist/commonjs/index.js +250 -0
- package/dist/commonjs/index.js.map +1 -0
- package/dist/commonjs/load-parse.d.ts +20 -0
- package/dist/commonjs/load-parse.d.ts.map +1 -0
- package/dist/commonjs/load-parse.js +34 -0
- package/dist/commonjs/load-parse.js.map +1 -0
- package/dist/commonjs/load.d.ts +91 -0
- package/dist/commonjs/load.d.ts.map +1 -0
- package/dist/commonjs/load.js +165 -0
- package/dist/commonjs/load.js.map +1 -0
- package/dist/commonjs/options.d.ts +98 -0
- package/dist/commonjs/options.d.ts.map +1 -0
- package/dist/commonjs/options.js +37 -0
- package/dist/commonjs/options.js.map +1 -0
- package/dist/commonjs/package.json +3 -0
- package/dist/commonjs/parse.d.ts +18 -0
- package/dist/commonjs/parse.d.ts.map +1 -0
- package/dist/commonjs/parse.js +77 -0
- package/dist/commonjs/parse.js.map +1 -0
- package/dist/commonjs/parsers/parse5-adapter.d.ts +20 -0
- package/dist/commonjs/parsers/parse5-adapter.d.ts.map +1 -0
- package/dist/commonjs/parsers/parse5-adapter.js +54 -0
- package/dist/commonjs/parsers/parse5-adapter.js.map +1 -0
- package/dist/commonjs/slim.d.ts +25 -0
- package/dist/commonjs/slim.d.ts.map +1 -0
- package/dist/commonjs/slim.js +30 -0
- package/dist/commonjs/slim.js.map +1 -0
- package/dist/commonjs/static.d.ts +112 -0
- package/dist/commonjs/static.d.ts.map +1 -0
- package/dist/commonjs/static.js +214 -0
- package/dist/commonjs/static.js.map +1 -0
- package/dist/commonjs/types.d.ts +21 -0
- package/dist/commonjs/types.d.ts.map +1 -0
- package/dist/commonjs/types.js +4 -0
- package/dist/commonjs/types.js.map +1 -0
- package/dist/commonjs/utils.d.ts +55 -0
- package/dist/commonjs/utils.d.ts.map +1 -0
- package/dist/commonjs/utils.js +91 -0
- package/dist/commonjs/utils.js.map +1 -0
- package/dist/esm/api/attributes.d.ts +385 -0
- package/dist/esm/api/attributes.d.ts.map +1 -0
- package/dist/esm/api/attributes.js +636 -0
- package/dist/esm/api/attributes.js.map +1 -0
- package/dist/esm/api/css.d.ts +42 -0
- package/dist/esm/api/css.d.ts.map +1 -0
- package/dist/esm/api/css.js +116 -0
- package/dist/esm/api/css.js.map +1 -0
- package/dist/esm/api/extract.d.ts +27 -0
- package/dist/esm/api/extract.d.ts.map +1 -0
- package/dist/esm/api/extract.js +42 -0
- package/dist/esm/api/extract.js.map +1 -0
- package/dist/esm/api/forms.d.ts +36 -0
- package/dist/esm/api/forms.d.ts.map +1 -0
- package/dist/esm/api/forms.js +81 -0
- package/dist/esm/api/forms.js.map +1 -0
- package/dist/esm/api/manipulation.d.ts +528 -0
- package/dist/esm/api/manipulation.d.ts.map +1 -0
- package/dist/esm/api/manipulation.js +831 -0
- package/dist/esm/api/manipulation.js.map +1 -0
- package/dist/esm/api/traversing.d.ts +657 -0
- package/dist/esm/api/traversing.d.ts.map +1 -0
- package/dist/esm/api/traversing.js +857 -0
- package/dist/esm/api/traversing.js.map +1 -0
- package/dist/esm/cheerio.d.ts +85 -0
- package/dist/esm/cheerio.d.ts.map +1 -0
- package/dist/esm/cheerio.js +58 -0
- package/dist/esm/cheerio.js.map +1 -0
- package/dist/esm/index.d.ts +104 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +202 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/load-parse.d.ts +20 -0
- package/dist/esm/load-parse.d.ts.map +1 -0
- package/dist/esm/load-parse.js +28 -0
- package/dist/esm/load-parse.js.map +1 -0
- package/dist/esm/load.d.ts +91 -0
- package/dist/esm/load.d.ts.map +1 -0
- package/dist/esm/load.js +129 -0
- package/dist/esm/load.js.map +1 -0
- package/dist/esm/options.d.ts +98 -0
- package/dist/esm/options.d.ts.map +1 -0
- package/dist/esm/options.js +34 -0
- package/dist/esm/options.js.map +1 -0
- package/dist/esm/package.json +3 -0
- package/dist/esm/parse.d.ts +18 -0
- package/dist/esm/parse.d.ts.map +1 -0
- package/dist/esm/parse.js +73 -0
- package/dist/esm/parse.js.map +1 -0
- package/dist/esm/parsers/parse5-adapter.d.ts +20 -0
- package/dist/esm/parsers/parse5-adapter.d.ts.map +1 -0
- package/dist/esm/parsers/parse5-adapter.js +50 -0
- package/dist/esm/parsers/parse5-adapter.js.map +1 -0
- package/dist/esm/slim.d.ts +25 -0
- package/dist/esm/slim.d.ts.map +1 -0
- package/dist/esm/slim.js +22 -0
- package/dist/esm/slim.js.map +1 -0
- package/dist/esm/static.d.ts +112 -0
- package/dist/esm/static.d.ts.map +1 -0
- package/dist/esm/static.js +204 -0
- package/dist/esm/static.js.map +1 -0
- package/dist/esm/types.d.ts +21 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +55 -0
- package/dist/esm/utils.d.ts.map +1 -0
- package/dist/esm/utils.js +84 -0
- package/dist/esm/utils.js.map +1 -0
- package/package.json +219 -0
- package/src/api/attributes.ts +1145 -0
- package/src/api/css.ts +224 -0
- package/src/api/extract.ts +92 -0
- package/src/api/forms.ts +103 -0
- package/src/api/manipulation.ts +1115 -0
- package/src/api/traversing.ts +1175 -0
- package/src/cheerio.ts +143 -0
- package/src/index-browser.mts +10 -0
- package/src/index.ts +294 -0
- package/src/load-parse.ts +39 -0
- package/src/load.ts +282 -0
- package/src/options.ts +136 -0
- package/src/parse.ts +105 -0
- package/src/parsers/parse5-adapter.ts +66 -0
- package/src/slim.ts +33 -0
- package/src/static.ts +312 -0
- package/src/types.ts +58 -0
- package/src/utils.ts +99 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { type CheerioOptions, type InternalOptions } from './options.js';
|
|
2
|
+
import * as staticMethods from './static.js';
|
|
3
|
+
import { Cheerio } from './cheerio.js';
|
|
4
|
+
import type { AnyNode, Document, Element } from 'domhandler';
|
|
5
|
+
import type { SelectorType, BasicAcceptedElems } from './types.js';
|
|
6
|
+
type StaticType = typeof staticMethods;
|
|
7
|
+
/**
|
|
8
|
+
* A querying function, bound to a document created from the provided markup.
|
|
9
|
+
*
|
|
10
|
+
* Also provides several helper methods for dealing with the document as a
|
|
11
|
+
* whole.
|
|
12
|
+
*/
|
|
13
|
+
export interface CheerioAPI extends StaticType {
|
|
14
|
+
/**
|
|
15
|
+
* This selector method is the starting point for traversing and manipulating
|
|
16
|
+
* the document. Like jQuery, it's the primary method for selecting elements
|
|
17
|
+
* in the document.
|
|
18
|
+
*
|
|
19
|
+
* `selector` searches within the `context` scope, which searches within the
|
|
20
|
+
* `root` scope.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
*
|
|
24
|
+
* ```js
|
|
25
|
+
* $('ul .pear').attr('class');
|
|
26
|
+
* //=> pear
|
|
27
|
+
*
|
|
28
|
+
* $('li[class=orange]').html();
|
|
29
|
+
* //=> Orange
|
|
30
|
+
*
|
|
31
|
+
* $('.apple', '#fruits').text();
|
|
32
|
+
* //=> Apple
|
|
33
|
+
* ```
|
|
34
|
+
*
|
|
35
|
+
* Optionally, you can also load HTML by passing the string as the selector:
|
|
36
|
+
*
|
|
37
|
+
* ```js
|
|
38
|
+
* $('<ul id="fruits">...</ul>');
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Or the context:
|
|
42
|
+
*
|
|
43
|
+
* ```js
|
|
44
|
+
* $('ul', '<ul id="fruits">...</ul>');
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* Or as the root:
|
|
48
|
+
*
|
|
49
|
+
* ```js
|
|
50
|
+
* $('li', 'ul', '<ul id="fruits">...</ul>');
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param selector - Either a selector to look for within the document, or the
|
|
54
|
+
* contents of a new Cheerio instance.
|
|
55
|
+
* @param context - Either a selector to look for within the root, or the
|
|
56
|
+
* contents of the document to query.
|
|
57
|
+
* @param root - Optional HTML document string.
|
|
58
|
+
*/
|
|
59
|
+
<T extends AnyNode, S extends string>(selector?: S | BasicAcceptedElems<T>, context?: BasicAcceptedElems<AnyNode> | null, root?: BasicAcceptedElems<Document>, options?: CheerioOptions): Cheerio<S extends SelectorType ? Element : T>;
|
|
60
|
+
/**
|
|
61
|
+
* The root the document was originally loaded with.
|
|
62
|
+
*
|
|
63
|
+
* @private
|
|
64
|
+
*/
|
|
65
|
+
_root: Document;
|
|
66
|
+
/**
|
|
67
|
+
* The options the document was originally loaded with.
|
|
68
|
+
*
|
|
69
|
+
* @private
|
|
70
|
+
*/
|
|
71
|
+
_options: InternalOptions;
|
|
72
|
+
/** Mimic jQuery's prototype alias for plugin authors. */
|
|
73
|
+
fn: typeof Cheerio.prototype;
|
|
74
|
+
/**
|
|
75
|
+
* The `.load` static method defined on the "loaded" Cheerio factory function
|
|
76
|
+
* is deprecated. Users are encouraged to instead use the `load` function
|
|
77
|
+
* exported by the Cheerio module.
|
|
78
|
+
*
|
|
79
|
+
* @deprecated Use the `load` function exported by the Cheerio module.
|
|
80
|
+
* @category Deprecated
|
|
81
|
+
* @example
|
|
82
|
+
*
|
|
83
|
+
* ```js
|
|
84
|
+
* const $ = cheerio.load('<h1>Hello, <span>world</span>.</h1>');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
load: ReturnType<typeof getLoad>;
|
|
88
|
+
}
|
|
89
|
+
export declare function getLoad(parse: Cheerio<AnyNode>['_parse'], render: (dom: AnyNode | ArrayLike<AnyNode>, options: InternalOptions) => string): (content: string | AnyNode | AnyNode[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean) => CheerioAPI;
|
|
90
|
+
export {};
|
|
91
|
+
//# sourceMappingURL=load.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.d.ts","sourceRoot":"","sources":["../../src/load.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EAErB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,aAAa,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAc,MAAM,YAAY,CAAC;AACzE,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGnE,KAAK,UAAU,GAAG,OAAO,aAAa,CAAC;AAEvC;;;;;GAKG;AACH,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,CAAC,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,MAAM,EAClC,QAAQ,CAAC,EAAE,CAAC,GAAG,kBAAkB,CAAC,CAAC,CAAC,EACpC,OAAO,CAAC,EAAE,kBAAkB,CAAC,OAAO,CAAC,GAAG,IAAI,EAC5C,IAAI,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,EACnC,OAAO,CAAC,EAAE,cAAc,GACvB,OAAO,CAAC,CAAC,SAAS,YAAY,GAAG,OAAO,GAAG,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,KAAK,EAAE,QAAQ,CAAC;IAEhB;;;;OAIG;IACH,QAAQ,EAAE,eAAe,CAAC;IAE1B,yDAAyD;IACzD,EAAE,EAAE,OAAO,OAAO,CAAC,SAAS,CAAC;IAE7B;;;;;;;;;;;;OAYG;IACH,IAAI,EAAE,UAAU,CAAC,OAAO,OAAO,CAAC,CAAC;CAClC;AAED,wBAAgB,OAAO,CACrB,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC,QAAQ,CAAC,EACjC,MAAM,EAAE,CACN,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,EACjC,OAAO,EAAE,eAAe,KACrB,MAAM,IAiBT,SAAS,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,GAAG,MAAM,EAC9C,UAAU,cAAc,GAAG,IAAI,EAC/B,oBAAiB,KAChB,UAAU,CAyId"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.getLoad = getLoad;
|
|
37
|
+
const options_js_1 = require("./options.js");
|
|
38
|
+
const staticMethods = __importStar(require("./static.js"));
|
|
39
|
+
const cheerio_js_1 = require("./cheerio.js");
|
|
40
|
+
const utils_js_1 = require("./utils.js");
|
|
41
|
+
const htmlparser2_1 = require("htmlparser2");
|
|
42
|
+
function getLoad(parse, render) {
|
|
43
|
+
/**
|
|
44
|
+
* Create a querying function, bound to a document created from the provided
|
|
45
|
+
* markup.
|
|
46
|
+
*
|
|
47
|
+
* Note that similar to web browser contexts, this operation may introduce
|
|
48
|
+
* `<html>`, `<head>`, and `<body>` elements; set `isDocument` to `false` to
|
|
49
|
+
* switch to fragment mode and disable this.
|
|
50
|
+
*
|
|
51
|
+
* @param content - Markup to be loaded.
|
|
52
|
+
* @param options - Options for the created instance.
|
|
53
|
+
* @param isDocument - Allows parser to be switched to fragment mode.
|
|
54
|
+
* @returns The loaded document.
|
|
55
|
+
* @see {@link https://cheerio.js.org/docs/basics/loading#load} for additional usage information.
|
|
56
|
+
*/
|
|
57
|
+
return function load(content, options, isDocument = true) {
|
|
58
|
+
if (content == null) {
|
|
59
|
+
throw new Error('cheerio.load() expects a string');
|
|
60
|
+
}
|
|
61
|
+
const internalOpts = (0, options_js_1.flattenOptions)(options);
|
|
62
|
+
const initialRoot = parse(content, internalOpts, isDocument, null);
|
|
63
|
+
/**
|
|
64
|
+
* Create an extended class here, so that extensions only live on one
|
|
65
|
+
* instance.
|
|
66
|
+
*/
|
|
67
|
+
class LoadedCheerio extends cheerio_js_1.Cheerio {
|
|
68
|
+
_make(selector, context) {
|
|
69
|
+
const cheerio = initialize(selector, context);
|
|
70
|
+
cheerio.prevObject = this;
|
|
71
|
+
return cheerio;
|
|
72
|
+
}
|
|
73
|
+
_parse(content, options, isDocument, context) {
|
|
74
|
+
return parse(content, options, isDocument, context);
|
|
75
|
+
}
|
|
76
|
+
_render(dom) {
|
|
77
|
+
return render(dom, this.options);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
function initialize(selector, context, root = initialRoot, opts) {
|
|
81
|
+
// $($)
|
|
82
|
+
if (selector && (0, utils_js_1.isCheerio)(selector))
|
|
83
|
+
return selector;
|
|
84
|
+
const options = (0, options_js_1.flattenOptions)(opts, internalOpts);
|
|
85
|
+
const r = typeof root === 'string'
|
|
86
|
+
? [parse(root, options, false, null)]
|
|
87
|
+
: 'length' in root
|
|
88
|
+
? root
|
|
89
|
+
: [root];
|
|
90
|
+
const rootInstance = (0, utils_js_1.isCheerio)(r)
|
|
91
|
+
? r
|
|
92
|
+
: new LoadedCheerio(r, null, options);
|
|
93
|
+
// Add a cyclic reference, so that calling methods on `_root` never fails.
|
|
94
|
+
rootInstance._root = rootInstance;
|
|
95
|
+
// $(), $(null), $(undefined), $(false)
|
|
96
|
+
if (!selector) {
|
|
97
|
+
return new LoadedCheerio(undefined, rootInstance, options);
|
|
98
|
+
}
|
|
99
|
+
const elements = typeof selector === 'string' && (0, utils_js_1.isHtml)(selector)
|
|
100
|
+
? // $(<html>)
|
|
101
|
+
parse(selector, options, false, null).children
|
|
102
|
+
: isNode(selector)
|
|
103
|
+
? // $(dom)
|
|
104
|
+
[selector]
|
|
105
|
+
: Array.isArray(selector)
|
|
106
|
+
? // $([dom])
|
|
107
|
+
selector
|
|
108
|
+
: undefined;
|
|
109
|
+
const instance = new LoadedCheerio(elements, rootInstance, options);
|
|
110
|
+
if (elements) {
|
|
111
|
+
return instance;
|
|
112
|
+
}
|
|
113
|
+
if (typeof selector !== 'string') {
|
|
114
|
+
throw new TypeError('Unexpected type of selector');
|
|
115
|
+
}
|
|
116
|
+
// We know that our selector is a string now.
|
|
117
|
+
let search = selector;
|
|
118
|
+
const searchContext = context
|
|
119
|
+
? // If we don't have a context, maybe we have a root, from loading
|
|
120
|
+
typeof context === 'string'
|
|
121
|
+
? (0, utils_js_1.isHtml)(context)
|
|
122
|
+
? // $('li', '<ul>...</ul>')
|
|
123
|
+
new LoadedCheerio([parse(context, options, false, null)], rootInstance, options)
|
|
124
|
+
: // $('li', 'ul')
|
|
125
|
+
((search = `${context} ${search}`), rootInstance)
|
|
126
|
+
: (0, utils_js_1.isCheerio)(context)
|
|
127
|
+
? // $('li', $)
|
|
128
|
+
context
|
|
129
|
+
: // $('li', node), $('li', [nodes])
|
|
130
|
+
new LoadedCheerio(Array.isArray(context) ? context : [context], rootInstance, options)
|
|
131
|
+
: rootInstance;
|
|
132
|
+
// If we still don't have a context, return
|
|
133
|
+
if (!searchContext)
|
|
134
|
+
return instance;
|
|
135
|
+
/*
|
|
136
|
+
* #id, .class, tag
|
|
137
|
+
*/
|
|
138
|
+
return searchContext.find(search);
|
|
139
|
+
}
|
|
140
|
+
// Add in static methods & properties
|
|
141
|
+
Object.assign(initialize, staticMethods, {
|
|
142
|
+
load,
|
|
143
|
+
// `_root` and `_options` are used in static methods.
|
|
144
|
+
_root: initialRoot,
|
|
145
|
+
_options: internalOpts,
|
|
146
|
+
// Add `fn` for plugins
|
|
147
|
+
fn: LoadedCheerio.prototype,
|
|
148
|
+
// Add the prototype here to maintain `instanceof` behavior.
|
|
149
|
+
prototype: LoadedCheerio.prototype,
|
|
150
|
+
});
|
|
151
|
+
return initialize;
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function isNode(obj) {
|
|
155
|
+
return (
|
|
156
|
+
// @ts-expect-error: TS doesn't know about the `name` property.
|
|
157
|
+
!!obj.name ||
|
|
158
|
+
// @ts-expect-error: TS doesn't know about the `type` property.
|
|
159
|
+
obj.type === htmlparser2_1.ElementType.Root ||
|
|
160
|
+
// @ts-expect-error: TS doesn't know about the `type` property.
|
|
161
|
+
obj.type === htmlparser2_1.ElementType.Text ||
|
|
162
|
+
// @ts-expect-error: TS doesn't know about the `type` property.
|
|
163
|
+
obj.type === htmlparser2_1.ElementType.Comment);
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=load.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load.js","sourceRoot":"","sources":["../../src/load.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0GA,0BAkKC;AA5QD,6CAIsB;AACtB,2DAA6C;AAC7C,6CAAuC;AACvC,yCAA+C;AAG/C,6CAA0C;AAgG1C,SAAgB,OAAO,CACrB,KAAiC,EACjC,MAGW;IAEX;;;;;;;;;;;;;OAaG;IACH,OAAO,SAAS,IAAI,CAClB,OAA8C,EAC9C,OAA+B,EAC/B,UAAU,GAAG,IAAI;QAEjB,IAAK,OAAyB,IAAI,IAAI,EAAE,CAAC;YACvC,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACrD,CAAC;QAED,MAAM,YAAY,GAAG,IAAA,2BAAc,EAAC,OAAO,CAAC,CAAC;QAC7C,MAAM,WAAW,GAAG,KAAK,CAAC,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,IAAI,CAAC,CAAC;QAEnE;;;WAGG;QACH,MAAM,aAAiB,SAAQ,oBAAU;YACvC,KAAK,CACH,QAAoC,EACpC,OAA4C;gBAE5C,MAAM,OAAO,GAAG,UAAU,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAC9C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC;gBA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,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,EAC5C,YAAY,EACZ,OAAO,CACR;gBACP,CAAC,CAAC,YAAY,CAAC;YAEjB,2CAA2C;YAC3C,IAAI,CAAC,aAAa;gBAAE,OAAO,QAA2B,CAAC;YAEvD;;eAEG;YACH,OAAO,aAAa,CAAC,IAAI,CAAC,MAAM,CAAoB,CAAC;QACvD,CAAC;QAED,qCAAqC;QACrC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,aAAa,EAAE;YACvC,IAAI;YACJ,qDAAqD;YACrD,KAAK,EAAE,WAAW;YAClB,QAAQ,EAAE,YAAY;YACtB,uBAAuB;YACvB,EAAE,EAAE,aAAa,CAAC,SAAS;YAC3B,4DAA4D;YAC5D,SAAS,EAAE,aAAa,CAAC,SAAS;SACnC,CAAC,CAAC;QAEH,OAAO,UAAwB,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,GAAY;IAC1B,OAAO;IACL,+DAA+D;IAC/D,CAAC,CAAC,GAAG,CAAC,IAAI;QACV,+DAA+D;QAC/D,GAAG,CAAC,IAAI,KAAK,yBAAW,CAAC,IAAI;QAC7B,+DAA+D;QAC/D,GAAG,CAAC,IAAI,KAAK,yBAAW,CAAC,IAAI;QAC7B,+DAA+D;QAC/D,GAAG,CAAC,IAAI,KAAK,yBAAW,CAAC,OAAO,CACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { DomHandlerOptions } from 'domhandler';
|
|
2
|
+
import type { ParserOptions as HTMLParser2ParserOptions } from 'htmlparser2';
|
|
3
|
+
import type { ParserOptions as Parse5ParserOptions } from 'parse5';
|
|
4
|
+
import type { Htmlparser2TreeAdapterMap } from 'parse5-htmlparser2-tree-adapter';
|
|
5
|
+
import type { Options as SelectOptions } from 'cheerio-select';
|
|
6
|
+
import type { DomSerializerOptions } from 'dom-serializer';
|
|
7
|
+
/**
|
|
8
|
+
* Options accepted by htmlparser2, the default parser for XML.
|
|
9
|
+
*
|
|
10
|
+
* @see https://github.com/fb55/htmlparser2/wiki/Parser-options
|
|
11
|
+
*/
|
|
12
|
+
export interface HTMLParser2Options extends DomHandlerOptions, DomSerializerOptions, HTMLParser2ParserOptions {
|
|
13
|
+
/** Treat the input as an XML document. */
|
|
14
|
+
xmlMode?: boolean;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options accepted by Cheerio.
|
|
18
|
+
*
|
|
19
|
+
* Please note that parser-specific options are _only recognized_ if the
|
|
20
|
+
* relevant parser is used.
|
|
21
|
+
*/
|
|
22
|
+
export interface CheerioOptions extends Parse5ParserOptions<Htmlparser2TreeAdapterMap> {
|
|
23
|
+
/**
|
|
24
|
+
* Recommended way of configuring htmlparser2 when wanting to parse XML.
|
|
25
|
+
*
|
|
26
|
+
* This will switch Cheerio to use htmlparser2.
|
|
27
|
+
*
|
|
28
|
+
* @default false
|
|
29
|
+
*/
|
|
30
|
+
xml?: HTMLParser2Options | boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Enable xml mode, which will switch Cheerio to use htmlparser2.
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Please use the `xml` option instead.
|
|
35
|
+
* @default false
|
|
36
|
+
*/
|
|
37
|
+
xmlMode?: boolean;
|
|
38
|
+
/** The base URI for the document. Used to resolve the `href` and `src` props. */
|
|
39
|
+
baseURI?: string | URL;
|
|
40
|
+
/**
|
|
41
|
+
* Is the document in quirks mode?
|
|
42
|
+
*
|
|
43
|
+
* This will lead to `.className` and `#id` being case-insensitive.
|
|
44
|
+
*
|
|
45
|
+
* @default false
|
|
46
|
+
*/
|
|
47
|
+
quirksMode?: SelectOptions['quirksMode'];
|
|
48
|
+
/**
|
|
49
|
+
* Extension point for pseudo-classes.
|
|
50
|
+
*
|
|
51
|
+
* Maps from names to either strings of functions.
|
|
52
|
+
*
|
|
53
|
+
* - A string value is a selector that the element must match to be selected.
|
|
54
|
+
* - A function is called with the element as its first argument, and optional
|
|
55
|
+
* parameters second. If it returns true, the element is selected.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
*
|
|
59
|
+
* ```js
|
|
60
|
+
* const $ = cheerio.load(
|
|
61
|
+
* '<div class="foo"></div><div data-bar="boo"></div>',
|
|
62
|
+
* {
|
|
63
|
+
* pseudos: {
|
|
64
|
+
* // `:foo` is an alias for `div.foo`
|
|
65
|
+
* foo: 'div.foo',
|
|
66
|
+
* // `:bar(val)` is equivalent to `[data-bar=val s]`
|
|
67
|
+
* bar: (el, val) => el.attribs['data-bar'] === val,
|
|
68
|
+
* },
|
|
69
|
+
* },
|
|
70
|
+
* );
|
|
71
|
+
*
|
|
72
|
+
* $(':foo').length; // 1
|
|
73
|
+
* $('div:bar(boo)').length; // 1
|
|
74
|
+
* $('div:bar(baz)').length; // 0
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
pseudos?: SelectOptions['pseudos'];
|
|
78
|
+
}
|
|
79
|
+
/** Internal options for Cheerio. */
|
|
80
|
+
export interface InternalOptions extends HTMLParser2Options, Omit<CheerioOptions, 'xml'> {
|
|
81
|
+
/**
|
|
82
|
+
* Whether to use htmlparser2.
|
|
83
|
+
*
|
|
84
|
+
* This is set to true if `xml` is set to true.
|
|
85
|
+
*/
|
|
86
|
+
_useHtmlParser2?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Flatten the options for Cheerio.
|
|
90
|
+
*
|
|
91
|
+
* This will set `_useHtmlParser2` to true if `xml` is set to true.
|
|
92
|
+
*
|
|
93
|
+
* @param options - The options to flatten.
|
|
94
|
+
* @param baseOptions - The base options to use.
|
|
95
|
+
* @returns The flattened options.
|
|
96
|
+
*/
|
|
97
|
+
export declare function flattenOptions(options?: CheerioOptions | null, baseOptions?: InternalOptions): InternalOptions;
|
|
98
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
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EAAE,cAAc,GAAG,IAAI,EAC/B,WAAW,CAAC,EAAE,eAAe,GAC5B,eAAe,CAuBjB"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.flattenOptions = flattenOptions;
|
|
4
|
+
const defaultOpts = {
|
|
5
|
+
_useHtmlParser2: false,
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Flatten the options for Cheerio.
|
|
9
|
+
*
|
|
10
|
+
* This will set `_useHtmlParser2` to true if `xml` is set to true.
|
|
11
|
+
*
|
|
12
|
+
* @param options - The options to flatten.
|
|
13
|
+
* @param baseOptions - The base options to use.
|
|
14
|
+
* @returns The flattened options.
|
|
15
|
+
*/
|
|
16
|
+
function flattenOptions(options, baseOptions) {
|
|
17
|
+
if (!options) {
|
|
18
|
+
return baseOptions !== null && baseOptions !== void 0 ? baseOptions : defaultOpts;
|
|
19
|
+
}
|
|
20
|
+
const opts = {
|
|
21
|
+
_useHtmlParser2: !!options.xmlMode,
|
|
22
|
+
...baseOptions,
|
|
23
|
+
...options,
|
|
24
|
+
};
|
|
25
|
+
if (options.xml) {
|
|
26
|
+
opts._useHtmlParser2 = true;
|
|
27
|
+
opts.xmlMode = true;
|
|
28
|
+
if (options.xml !== true) {
|
|
29
|
+
Object.assign(opts, options.xml);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else if (options.xmlMode) {
|
|
33
|
+
opts._useHtmlParser2 = true;
|
|
34
|
+
}
|
|
35
|
+
return opts;
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../../src/options.ts"],"names":[],"mappings":";;AA6GA,wCA0BC;AAvCD,MAAM,WAAW,GAAoB;IACnC,eAAe,EAAE,KAAK;CACvB,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,cAAc,CAC5B,OAA+B,EAC/B,WAA6B;IAE7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,OAAO,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,WAAW,CAAC;IACpC,CAAC;IAED,MAAM,IAAI,GAAoB;QAC5B,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO;QAClC,GAAG,WAAW;QACd,GAAG,OAAO;KACX,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;QAChB,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QAEpB,IAAI,OAAO,CAAC,GAAG,KAAK,IAAI,EAAE,CAAC;YACzB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;SAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;QAC3B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC;IAC9B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type AnyNode, Document, type ParentNode } from 'domhandler';
|
|
2
|
+
import type { InternalOptions } from './options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Get the parse function with options.
|
|
5
|
+
*
|
|
6
|
+
* @param parser - The parser function.
|
|
7
|
+
* @returns The parse function with options.
|
|
8
|
+
*/
|
|
9
|
+
export declare function getParse(parser: (content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null) => Document): (content: string | Document | AnyNode | AnyNode[] | Buffer, options: InternalOptions, isDocument: boolean, context: ParentNode | null) => Document;
|
|
10
|
+
/**
|
|
11
|
+
* Update the dom structure, for one changed layer.
|
|
12
|
+
*
|
|
13
|
+
* @param newChilds - The new children.
|
|
14
|
+
* @param parent - The new parent.
|
|
15
|
+
* @returns The parent node.
|
|
16
|
+
*/
|
|
17
|
+
export declare function update(newChilds: AnyNode[] | AnyNode, parent: ParentNode | null): ParentNode | null;
|
|
18
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,OAAO,EACZ,QAAQ,EACR,KAAK,UAAU,EAEhB,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,MAAM,EAAE,CACN,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,UAAU,GAAG,IAAI,KACvB,QAAQ,IAYX,SAAS,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,EAAE,GAAG,MAAM,EACzD,SAAS,eAAe,EACxB,YAAY,OAAO,EACnB,SAAS,UAAU,GAAG,IAAI,KACzB,QAAQ,CAwBZ;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,OAAO,EAAE,GAAG,OAAO,EAC9B,MAAM,EAAE,UAAU,GAAG,IAAI,GACxB,UAAU,GAAG,IAAI,CA+BnB"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getParse = getParse;
|
|
4
|
+
exports.update = update;
|
|
5
|
+
const domutils_1 = require("domutils");
|
|
6
|
+
const domhandler_1 = require("domhandler");
|
|
7
|
+
/**
|
|
8
|
+
* Get the parse function with options.
|
|
9
|
+
*
|
|
10
|
+
* @param parser - The parser function.
|
|
11
|
+
* @returns The parse function with options.
|
|
12
|
+
*/
|
|
13
|
+
function getParse(parser) {
|
|
14
|
+
/**
|
|
15
|
+
* Parse a HTML string or a node.
|
|
16
|
+
*
|
|
17
|
+
* @param content - The HTML string or node.
|
|
18
|
+
* @param options - The parser options.
|
|
19
|
+
* @param isDocument - If `content` is a document.
|
|
20
|
+
* @param context - The context node in the DOM tree.
|
|
21
|
+
* @returns The parsed document node.
|
|
22
|
+
*/
|
|
23
|
+
return function parse(content, options, isDocument, context) {
|
|
24
|
+
if (typeof Buffer !== 'undefined' && Buffer.isBuffer(content)) {
|
|
25
|
+
content = content.toString();
|
|
26
|
+
}
|
|
27
|
+
if (typeof content === 'string') {
|
|
28
|
+
return parser(content, options, isDocument, context);
|
|
29
|
+
}
|
|
30
|
+
const doc = content;
|
|
31
|
+
if (!Array.isArray(doc) && (0, domhandler_1.isDocument)(doc)) {
|
|
32
|
+
// If `doc` is already a root, just return it
|
|
33
|
+
return doc;
|
|
34
|
+
}
|
|
35
|
+
// Add content to new root element
|
|
36
|
+
const root = new domhandler_1.Document([]);
|
|
37
|
+
// Update the DOM using the root
|
|
38
|
+
update(doc, root);
|
|
39
|
+
return root;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Update the dom structure, for one changed layer.
|
|
44
|
+
*
|
|
45
|
+
* @param newChilds - The new children.
|
|
46
|
+
* @param parent - The new parent.
|
|
47
|
+
* @returns The parent node.
|
|
48
|
+
*/
|
|
49
|
+
function update(newChilds, parent) {
|
|
50
|
+
// Normalize
|
|
51
|
+
const arr = Array.isArray(newChilds) ? newChilds : [newChilds];
|
|
52
|
+
// Update parent
|
|
53
|
+
if (parent) {
|
|
54
|
+
parent.children = arr;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
parent = null;
|
|
58
|
+
}
|
|
59
|
+
// Update neighbors
|
|
60
|
+
for (let i = 0; i < arr.length; i++) {
|
|
61
|
+
const node = arr[i];
|
|
62
|
+
// Cleanly remove existing nodes from their previous structures.
|
|
63
|
+
if (node.parent && node.parent.children !== arr) {
|
|
64
|
+
(0, domutils_1.removeElement)(node);
|
|
65
|
+
}
|
|
66
|
+
if (parent) {
|
|
67
|
+
node.prev = arr[i - 1] || null;
|
|
68
|
+
node.next = arr[i + 1] || null;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
node.prev = node.next = null;
|
|
72
|
+
}
|
|
73
|
+
node.parent = parent;
|
|
74
|
+
}
|
|
75
|
+
return parent;
|
|
76
|
+
}
|
|
77
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":";;AAeA,4BA8CC;AASD,wBAkCC;AAxGD,uCAAyC;AACzC,2CAKoB;AAGpB;;;;;GAKG;AACH,SAAgB,QAAQ,CACtB,MAKa;IAEb;;;;;;;;OAQG;IACH,OAAO,SAAS,KAAK,CACnB,OAAyD,EACzD,OAAwB,EACxB,UAAmB,EACnB,OAA0B;QAE1B,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC9D,OAAO,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;QAC/B,CAAC;QAED,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;QACvD,CAAC;QAED,MAAM,GAAG,GAAG,OAAyC,CAAC;QAEtD,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAA,uBAAe,EAAC,GAAG,CAAC,EAAE,CAAC;YAChD,6CAA6C;YAC7C,OAAO,GAAG,CAAC;QACb,CAAC;QAED,kCAAkC;QAClC,MAAM,IAAI,GAAG,IAAI,qBAAQ,CAAC,EAAE,CAAC,CAAC;QAE9B,gCAAgC;QAChC,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QAElB,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,MAAM,CACpB,SAA8B,EAC9B,MAAyB;IAEzB,YAAY;IACZ,MAAM,GAAG,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IAE/D,gBAAgB;IAChB,IAAI,MAAM,EAAE,CAAC;QACX,MAAM,CAAC,QAAQ,GAAG,GAAG,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,MAAM,GAAG,IAAI,CAAC;IAChB,CAAC;IAED,mBAAmB;IACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACpC,MAAM,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;QAEpB,gEAAgE;QAChE,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;YAChD,IAAA,wBAAa,EAAC,IAAI,CAAC,CAAC;QACtB,CAAC;QAED,IAAI,MAAM,EAAE,CAAC;YACX,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;YAC/B,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QAC/B,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type AnyNode, type Document, type ParentNode } from 'domhandler';
|
|
2
|
+
import type { InternalOptions } from '../options.js';
|
|
3
|
+
/**
|
|
4
|
+
* Parse the content with `parse5` in the context of the given `ParentNode`.
|
|
5
|
+
*
|
|
6
|
+
* @param content - The content to parse.
|
|
7
|
+
* @param options - A set of options to use to parse.
|
|
8
|
+
* @param isDocument - Whether to parse the content as a full HTML document.
|
|
9
|
+
* @param context - The context in which to parse the content.
|
|
10
|
+
* @returns The parsed content.
|
|
11
|
+
*/
|
|
12
|
+
export declare function parseWithParse5(content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document;
|
|
13
|
+
/**
|
|
14
|
+
* Renders the given DOM tree with `parse5` and returns the result as a string.
|
|
15
|
+
*
|
|
16
|
+
* @param dom - The DOM tree to render.
|
|
17
|
+
* @returns The rendered document.
|
|
18
|
+
*/
|
|
19
|
+
export declare function renderWithParse5(dom: AnyNode | ArrayLike<AnyNode>): string;
|
|
20
|
+
//# sourceMappingURL=parse5-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse5-adapter.d.ts","sourceRoot":"","sources":["../../../src/parsers/parse5-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,KAAK,UAAU,EAEhB,MAAM,YAAY,CAAC;AAGpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,eAAe,EACxB,UAAU,EAAE,OAAO,EACnB,OAAO,EAAE,UAAU,GAAG,IAAI,GACzB,QAAQ,CAUV;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,MAAM,CAqB1E"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseWithParse5 = parseWithParse5;
|
|
4
|
+
exports.renderWithParse5 = renderWithParse5;
|
|
5
|
+
const domhandler_1 = require("domhandler");
|
|
6
|
+
const parse5_1 = require("parse5");
|
|
7
|
+
const parse5_htmlparser2_tree_adapter_1 = require("parse5-htmlparser2-tree-adapter");
|
|
8
|
+
/**
|
|
9
|
+
* Parse the content with `parse5` in the context of the given `ParentNode`.
|
|
10
|
+
*
|
|
11
|
+
* @param content - The content to parse.
|
|
12
|
+
* @param options - A set of options to use to parse.
|
|
13
|
+
* @param isDocument - Whether to parse the content as a full HTML document.
|
|
14
|
+
* @param context - The context in which to parse the content.
|
|
15
|
+
* @returns The parsed content.
|
|
16
|
+
*/
|
|
17
|
+
function parseWithParse5(content, options, isDocument, context) {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = options.treeAdapter) !== null && _a !== void 0 ? _a : (options.treeAdapter = parse5_htmlparser2_tree_adapter_1.adapter);
|
|
20
|
+
if (options.scriptingEnabled !== false) {
|
|
21
|
+
options.scriptingEnabled = true;
|
|
22
|
+
}
|
|
23
|
+
return isDocument
|
|
24
|
+
? (0, parse5_1.parse)(content, options)
|
|
25
|
+
: (0, parse5_1.parseFragment)(context, content, options);
|
|
26
|
+
}
|
|
27
|
+
const renderOpts = { treeAdapter: parse5_htmlparser2_tree_adapter_1.adapter };
|
|
28
|
+
/**
|
|
29
|
+
* Renders the given DOM tree with `parse5` and returns the result as a string.
|
|
30
|
+
*
|
|
31
|
+
* @param dom - The DOM tree to render.
|
|
32
|
+
* @returns The rendered document.
|
|
33
|
+
*/
|
|
34
|
+
function renderWithParse5(dom) {
|
|
35
|
+
/*
|
|
36
|
+
* `dom-serializer` passes over the special "root" node and renders the
|
|
37
|
+
* node's children in its place. To mimic this behavior with `parse5`, an
|
|
38
|
+
* equivalent operation must be applied to the input array.
|
|
39
|
+
*/
|
|
40
|
+
const nodes = 'length' in dom ? dom : [dom];
|
|
41
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
42
|
+
const node = nodes[index];
|
|
43
|
+
if ((0, domhandler_1.isDocument)(node)) {
|
|
44
|
+
Array.prototype.splice.call(nodes, index, 1, ...node.children);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
let result = '';
|
|
48
|
+
for (let index = 0; index < nodes.length; index += 1) {
|
|
49
|
+
const node = nodes[index];
|
|
50
|
+
result += (0, parse5_1.serializeOuter)(node, renderOpts);
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=parse5-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse5-adapter.js","sourceRoot":"","sources":["../../../src/parsers/parse5-adapter.ts"],"names":[],"mappings":";;AAmBA,0CAeC;AAUD,4CAqBC;AAjED,2CAKoB;AACpB,mCAA+E;AAC/E,qFAAgF;AAGhF;;;;;;;;GAQG;AACH,SAAgB,eAAe,CAC7B,OAAe,EACf,OAAwB,EACxB,UAAmB,EACnB,OAA0B;;IAE1B,MAAA,OAAO,CAAC,WAAW,oCAAnB,OAAO,CAAC,WAAW,GAAK,yCAAkB,EAAC;IAE3C,IAAI,OAAO,CAAC,gBAAgB,KAAK,KAAK,EAAE,CAAC;QACvC,OAAO,CAAC,gBAAgB,GAAG,IAAI,CAAC;IAClC,CAAC;IAED,OAAO,UAAU;QACf,CAAC,CAAC,IAAA,cAAa,EAAC,OAAO,EAAE,OAAO,CAAC;QACjC,CAAC,CAAC,IAAA,sBAAa,EAAC,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,GAAG,EAAE,WAAW,EAAE,yCAAkB,EAAE,CAAC;AAEvD;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,GAAiC;IAChE;;;;OAIG;IACH,MAAM,KAAK,GAAG,QAAQ,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAC5C,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,IAAI,IAAA,uBAAU,EAAC,IAAI,CAAC,EAAE,CAAC;YACrB,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjE,CAAC;IACH,CAAC;IAED,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC1B,MAAM,IAAI,IAAA,uBAAc,EAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Alternative entry point for Cheerio that always uses htmlparser2. This
|
|
3
|
+
* way, parse5 won't be loaded, saving some memory.
|
|
4
|
+
*/
|
|
5
|
+
import { type CheerioAPI } from './load.js';
|
|
6
|
+
import { type CheerioOptions } from './options.js';
|
|
7
|
+
import type { AnyNode } from 'domhandler';
|
|
8
|
+
export { contains, merge } from './static.js';
|
|
9
|
+
export type * from './types.js';
|
|
10
|
+
export type { Cheerio } from './cheerio.js';
|
|
11
|
+
export type { CheerioOptions, HTMLParser2Options } from './options.js';
|
|
12
|
+
export type { CheerioAPI } from './load.js';
|
|
13
|
+
/**
|
|
14
|
+
* Create a querying function, bound to a document created from the provided
|
|
15
|
+
* markup.
|
|
16
|
+
*
|
|
17
|
+
* @param content - Markup to be loaded.
|
|
18
|
+
* @param options - Options for the created instance.
|
|
19
|
+
* @param isDocument - Always `false` here, as we are always using
|
|
20
|
+
* `htmlparser2`.
|
|
21
|
+
* @returns The loaded document.
|
|
22
|
+
* @see {@link https://cheerio.js.org#loading} for additional usage information.
|
|
23
|
+
*/
|
|
24
|
+
export declare const load: (content: string | AnyNode | AnyNode[] | Buffer, options?: CheerioOptions | null, isDocument?: boolean) => CheerioAPI;
|
|
25
|
+
//# sourceMappingURL=slim.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slim.d.ts","sourceRoot":"","sources":["../../src/slim.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,UAAU,EAAW,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAI1C,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAC9C,mBAAmB,YAAY,CAAC;AAChC,YAAY,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AACvE,YAAY,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAE5C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,IAAI,EAAE,CACjB,OAAO,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,EAAE,GAAG,MAAM,EAC9C,OAAO,CAAC,EAAE,cAAc,GAAG,IAAI,EAC/B,UAAU,CAAC,EAAE,OAAO,KACjB,UAAqD,CAAC"}
|