From 22a25ded9f7d9c9a96cce8d1bc12475ca0434201 Mon Sep 17 00:00:00 2001 From: Minteck Date: Wed, 9 Feb 2022 17:58:07 +0100 Subject: Major update --- node_modules/cheerio/lib/parse.js | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 node_modules/cheerio/lib/parse.js (limited to 'node_modules/cheerio/lib/parse.js') diff --git a/node_modules/cheerio/lib/parse.js b/node_modules/cheerio/lib/parse.js new file mode 100644 index 0000000..cd92fc9 --- /dev/null +++ b/node_modules/cheerio/lib/parse.js @@ -0,0 +1,67 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.update = void 0; +var htmlparser2_1 = require("htmlparser2"); +var htmlparser2_adapter_1 = require("./parsers/htmlparser2-adapter"); +var parse5_adapter_1 = require("./parsers/parse5-adapter"); +var domhandler_1 = require("domhandler"); +/* + * Parser + */ +function parse(content, options, isDocument) { + if (typeof Buffer !== 'undefined' && Buffer.isBuffer(content)) { + content = content.toString(); + } + if (typeof content === 'string') { + return options.xmlMode || options._useHtmlParser2 + ? htmlparser2_adapter_1.parse(content, options) + : parse5_adapter_1.parse(content, options, isDocument); + } + var doc = content; + if (!Array.isArray(doc) && domhandler_1.isDocument(doc)) { + // If `doc` is already a root, just return it + return doc; + } + // Add conent to new root element + var root = new domhandler_1.Document([]); + // Update the DOM using the root + update(doc, root); + return root; +} +exports.default = parse; +/** + * Update the dom structure, for one changed layer. + * + * @param newChilds - The new children. + * @param parent - The new parent. + * @returns The parent node. + */ +function update(newChilds, parent) { + // Normalize + var arr = Array.isArray(newChilds) ? newChilds : [newChilds]; + // Update parent + if (parent) { + parent.children = arr; + } + else { + parent = null; + } + // Update neighbors + for (var i = 0; i < arr.length; i++) { + var node = arr[i]; + // Cleanly remove existing nodes from their previous structures. + if (node.parent && node.parent.children !== arr) { + htmlparser2_1.DomUtils.removeElement(node); + } + if (parent) { + node.prev = arr[i - 1] || null; + node.next = arr[i + 1] || null; + } + else { + node.prev = node.next = null; + } + node.parent = parent; + } + return parent; +} +exports.update = update; -- cgit