This commit is contained in:
2025-05-12 05:38:44 +09:00
parent dced21c3f8
commit 6d78bfa46e
8120 changed files with 1161564 additions and 0 deletions

View File

@ -0,0 +1,20 @@
import { type AnyNode, type Document, type 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":"","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"}

View File

@ -0,0 +1,54 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseWithParse5 = parseWithParse5;
exports.renderWithParse5 = renderWithParse5;
const domhandler_1 = require("domhandler");
const parse5_1 = require("parse5");
const parse5_htmlparser2_tree_adapter_1 = require("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.
*/
function parseWithParse5(content, options, isDocument, context) {
var _a;
(_a = options.treeAdapter) !== null && _a !== void 0 ? _a : (options.treeAdapter = parse5_htmlparser2_tree_adapter_1.adapter);
if (options.scriptingEnabled !== false) {
options.scriptingEnabled = true;
}
return isDocument
? (0, parse5_1.parse)(content, options)
: (0, parse5_1.parseFragment)(context, content, options);
}
const renderOpts = { treeAdapter: parse5_htmlparser2_tree_adapter_1.adapter };
/**
* 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.
*/
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 ((0, domhandler_1.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 += (0, parse5_1.serializeOuter)(node, renderOpts);
}
return result;
}
//# sourceMappingURL=parse5-adapter.js.map

View File

@ -0,0 +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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