This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

View File

@@ -0,0 +1,20 @@
import { AnyNode, Document, ParentNode } from 'domhandler';
import type { InternalOptions } from '../options.js';
/**
* Parse the content with `parse5` in the context of the given `ParentNode`.
*
* @param content - The content to parse.
* @param options - A set of options to use to parse.
* @param isDocument - Whether to parse the content as a full HTML document.
* @param context - The context in which to parse the content.
* @returns The parsed content.
*/
export declare function parseWithParse5(content: string, options: InternalOptions, isDocument: boolean, context: ParentNode | null): Document;
/**
* Renders the given DOM tree with `parse5` and returns the result as a string.
*
* @param dom - The DOM tree to render.
* @returns The rendered document.
*/
export declare function renderWithParse5(dom: AnyNode | ArrayLike<AnyNode>): string;
//# sourceMappingURL=parse5-adapter.d.ts.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"parse5-adapter.d.ts","sourceRoot":"https://raw.githubusercontent.com/cheeriojs/cheerio/d1cbc66d53392ce8bf6cd0068f675836372d2bf3/src/","sources":["parsers/parse5-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAc,UAAU,EAAE,MAAM,YAAY,CAAC;AAGvE,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,CAaV;AAID;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,GAAG,MAAM,CAqB1E"}

52
node_modules/cheerio/lib/esm/parsers/parse5-adapter.js generated vendored Normal file
View File

@@ -0,0 +1,52 @@
import { isDocument } from 'domhandler';
import { parse as parseDocument, parseFragment, serializeOuter } from 'parse5';
import { adapter as htmlparser2Adapter } from 'parse5-htmlparser2-tree-adapter';
/**
* Parse the content with `parse5` in the context of the given `ParentNode`.
*
* @param content - The content to parse.
* @param options - A set of options to use to parse.
* @param isDocument - Whether to parse the content as a full HTML document.
* @param context - The context in which to parse the content.
* @returns The parsed content.
*/
export function parseWithParse5(content, options, isDocument, context) {
const opts = {
scriptingEnabled: typeof options.scriptingEnabled === 'boolean'
? options.scriptingEnabled
: true,
treeAdapter: htmlparser2Adapter,
sourceCodeLocationInfo: options.sourceCodeLocationInfo,
};
return isDocument
? parseDocument(content, opts)
: parseFragment(context, content, opts);
}
const renderOpts = { treeAdapter: htmlparser2Adapter };
/**
* Renders the given DOM tree with `parse5` and returns the result as a string.
*
* @param dom - The DOM tree to render.
* @returns The rendered document.
*/
export function renderWithParse5(dom) {
/*
* `dom-serializer` passes over the special "root" node and renders the
* node's children in its place. To mimic this behavior with `parse5`, an
* equivalent operation must be applied to the input array.
*/
const nodes = 'length' in dom ? dom : [dom];
for (let index = 0; index < nodes.length; index += 1) {
const node = nodes[index];
if (isDocument(node)) {
Array.prototype.splice.call(nodes, index, 1, ...node.children);
}
}
let result = '';
for (let index = 0; index < nodes.length; index += 1) {
const node = nodes[index];
result += serializeOuter(node, renderOpts);
}
return result;
}
//# sourceMappingURL=parse5-adapter.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"parse5-adapter.js","sourceRoot":"https://raw.githubusercontent.com/cheeriojs/cheerio/d1cbc66d53392ce8bf6cd0068f675836372d2bf3/src/","sources":["parsers/parse5-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,UAAU,EAAc,MAAM,YAAY,CAAC;AACvE,OAAO,EAAE,KAAK,IAAI,aAAa,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAGhF;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,OAAe,EACf,OAAwB,EAC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